Python 3D Graphics Tutorial 21: Understanding and Using Widgets in Vpython

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is paul mcquarter from toptechboy.com and we're here today with lesson number 21 in our incredible new tutorial series where you're learning how to do 3d graphics and 3d animations in python what i'm going to need you to do is for yourself a nice tall glass of iced coffee that would be straight up black coffee poured over ice no sugar no sweeteners none needed and as you're pouring your coffee as always i want to give a shout out to you guys who are helping me out over at patreon it is your support and your encouragement that keeps this great content coming you guys that are not helping out yet take a look down in the description there is a link over to my patreon account think about hopping on over there and hooking a brother up well enough of this shameless self-promotion let's jump in and talk about what i am going to teach you today and what i'm going to teach you is how to use visual python and how to make visual python more interactive by putting widgets on your animation and those widgets will allow you to interact with your animation and sort of affect what the animation is doing now the way we're doing that right now is we're just going in and coding it up differently now for us old python pros that's a fine strategy because we can go in and change things by changing the program but if we were going to like impress someone and let someone else run it they need to be able to interact with it without having to go in and change the code and so that my friend is what widgets are all about and that is what i'm going to teach you today so a lot of you that are following along in this series last week you took lesson number 20 and then this week you're not taking lesson number 21 and it seems like a week has elapsed well a week has elapsed for you but for me lesson 20 i actually made a year ago right because i was moving to africa i made like a whole bunch of videos so that i could release them week by week just in case i got over here and had trouble setting my studio up so last week's lesson was actually made a year ago and this week's lesson is made today have i aged well in a year or do i look like an old man compared to last week well anyway if i look a lot older it's because i'm one year older not just one week older but enough of this chit chat about me and my age and my move to africa why don't we go ahead over and what i will need you to do is call up your most excellent visual studio code and then we are going to come over here we are working in our main python folder and we are going to create a new program and that new program let's see what should we call it how about python widgets dot p y boom a fresh new python program just waiting to be written and my friend as always you know the dot p y is kind of important now i don't want to go in and like take the time to completely write a program from scratch and let's let's take one of the earlier one of the programs that we wrote in an earlier lesson and let's just start where we left off with that and then let's see if we can kind of start making it dynamic and interactive by adding widgets okay and i'll sort of show you examples of the different types of widgets that you can add and then you can just go to town with it adding these to all your other programs but what we probably need to do is start at the most excellent www.toptechboy.com you can come down here and use this happy little search box and you can search on something like python tutorial 3d gr python 3d graphics tutorial 5. that's the one that you want when you search on that you should come up with this code this was the most excellent code for the old bouncing ball in a box program remember that the old bouncing ball in a box program so let's click on those two little pages and that should copy the text for us and now we're going to come back to visual studio code and we are going to paste it in and then just to make sure that we can in fact copy and paste without breaking something we are going to come over here and we are going to run the program okay boom and here we got the little ball but bouncing in the box it looks like that i kind of left it at some sort of goofy size that box and so let me go ahead and kill the program and then we are going to need to come over here and i'm going to need to make the room here it's room width room depth room height and i have it 12 20 and 2 explaining the rather freakishly dimension box that we had what if we made this 15 that should make it a little bit easier to follow now just kind of real quick remember that we were doing parametric design on this program so we just set the room with the room depth and the room height those are the parameters that we set and then we we created the ceiling the ceiling the back wall the left wall the right wall all based on those parameters and then we created the marble which is the ball that's going to bounce around we set some other things up and then we just move that ball and if it hits a wall we changed its direction hopefully you remember that but what we're going to do today is we're going to look at and see if we can begin to customize and interact and and and sort of animate that more by putting some widgets and so i'll probably just start with some of the simpler ones and then we will go ahead and show you sort of the main widgets that you can do in uh in python and so in v python so i think what i would like to do is i would like to just start with a radio button you know a radio button is a round circle and then it's got some text beside it and then you can either click to select that button or you can click to deselect the button okay but just a little round radio button and so what we're going to do is the way we define a radio button is we call it radio that is the v python that's the kind of v python keyword you can't use anything there you got to use radio if you want a radio button and then what you got to do is you've got to bind it to a function okay so it's sort of like this this radio method is saying hey when you call radio when you click radio what do you want me to do we got to bind it to we have to bind it to a function so let me just call the function run radio you can call it anything you want but i'm going to call it run radio now why do we get the unhappy little squiggly because we haven't defined a function run radio yet well we'll do that right after we create the radio button and then anytime you click on that radio button it will run up and run that it will run up and run that function i hope that makes sense okay so we have bind um we are going to bind it to run radio and then we've got to put some text and so what tech what text do we want besides our little radio button well what i think we will say is uh what we will say is we are going to call it uh i'll just say run okay do you want it to run that's all i'm going to do is just say do you want it to run and that's really i should say that better that is just the label right now if we are going to call the function run radio what did we best do we bet best define the function what run radio now we need to pass it or run radio will be passed an x value so when we define the function we've got to catch it so this radio method when it calls run radio it's going to pass its pass it this parameter x and i'll explain a little bit more about that in the coming lines of code so now we have run radio and we are going to say uh what are we going to do we are going to just print and just print x dot c let or x dot checked okay so what we're going to see is is that little radio button checked or is that little radio button not checked and so something should actually happen now when we do this so let's go ahead and run it just to see just to see if we have created a widget that does something it's not going to do very much but let's see if we can create something that does something right now look there is boom there is our little let's see if i can make this a little bigger yeah i'm just zooming in a little bit so you can see a little better so we have this button and then we need to be able to look at our terminal because what we did was we just said print so we need to be able to see if anything is printing this is incredibly difficult today okay i think there and now i will just click run and what happens when i click run it printed true saying that it is now checked and if i click it again it unchecks it and it prints false so the good news is it looks like we are actually getting some action there out of our first widget yeah we made our first widget always feels good to do these simple things doesn't it but we want to do something probably a little bit better than that what i want to do is i want to have the ball running around only if run is checked if you uncheck run you want to kind of freeze the ball so the ball is only running when run is checked well if i'm going to do that then probably what i am going to need to do is i am going to need to come in here and i'm going to say well if x dot checked if that is checked then if x dot checked what e equal equal true that is saying it is checked then what do i want to do well i want to set run is equal to one okay then what i want to do is i want to say if x dot checked it checked is equal equal false then what do i want to do i want to set run equal to zero all right so i'm going to put run equal one if x checked is true and i'm going to put run equal 0 if x checked is false now i need to do something with run to make the ball move or not so what i'm going to do is down here in the main loop where i say the new position is equal to the old position plus delta x that just keeps moving now you could think inside that function to maybe set delta x equal to zero but then the problem is when you come back to set delta x to something other than 0 then you've kind of messed up your program setup so i don't want to do that but what i could do is i could say that x position is x position plus delta x times what times run okay and then similarly times run and then times run so what is going to happen here what is going to happen is if run is remains at one if it's checked then it's going to keep moving but when run becomes 0 the ball is going to stop because the term you're adding is going to be 0. so let's run this and see what happens okay and it looks like that the program crashed okay it looks like that the program crashed and what does it say run is not defined okay did you guys catch on what happened there i was kind of seeing if you were playing paying attention why does it not no not know what run is and why did the program crash well it crashed because by the when it goes there and we haven't gone into that function it's never seen run before i haven't clicked on that it didn't go inside of define so it doesn't know what run is so i better come in here and i better say run is equal to one and now it should uh you know now it should know it and it should it should not crash okay let's go ahead and run this now and see what happens okay it didn't crash and now the strange thing what is the strange behavior run is not selected and it is still going well now why is that well it is because i set run equal to 1 and i have not gone inside this function yet because i haven't clicked on it and so this has not set it to zero so if it's going to start if the box is going to be created unchecked then i better start with run equals zero so when the program runs it initializes all with the various parts working together so now this should work right okay boom run is set to uh run is set to uh not being checked and it's not running very good now let's click it boom it clicked but now it's not running somebody tell me why the ball isn't running even though that i selected it as run and now run is equal to true and then because run is equal to true i mean because x checked is equal to true now run should be equal to 1 but yet it isn't moving somebody tell me why is that right because these are the kind of errors that you have that are just really really really really hard to figure out okay this is what's going on remember in python inside of a function the variables you create inside that function are local variables so this run is a local variable that only this function knows about this run is a different run okay it's it's a global run but it doesn't go down inside of this function does that make sense so what do i need to do well if i'm going to do use variables inside of a function that i want the mother python program to know i've got to define them as global so what i need to do here is just say global run okay so that makes the run variable global and so what that's saying is hey guys this run is the same as this run okay i hope you guys we've done a lot in these lessons on methods and functions hopefully you caught that okay so let's kill this and let's run it again okay now we know when i click this that it's going to select it but is the ball going to run let's see boom look at that who's your huckleberry all right look at that now let's see if we can stop it and when we do that it stops and we come in again and it goes again wow how cool is that so we've done our first widget that actually does something to the uh to the simulation to the model and i think that is pretty cool so let's go ahead and kill that and let's look and see if we can learn a uh let's see if we can learn another another type of widget that we can build and what i'll do is i'll kind of do it the same way i'll build the uh widget and then above it i will put the i will build the widget and then above it i will put the function but besides a radio button what you can also do is you can also just do a check box and so i'm going to create a check box a check box and what you got to know is again check box this is calling a method in v python so you can't just call it anything you want it's very specific you say make a check box now what do i want to do i got to bind it to a function well what i want this function to do is to make a big ball or do you want a big ball yes or no okay so the the thing you're going to select is big ball so bind is going to go to a function that i will create and that function will be called big ball why do i get the unhappy little squiggly under big ball because i haven't defined it yet but we will take care of that in a minute and then again what text do i want beside it the text is going to be like this big ball so do you see the check box works almost identical pretty much identical to the radio the only difference is uh the uh the only difference is that uh you get a little square with a check mark instead of a round with a with a dot in it but other than that it is pretty much the same so let's come up here now and we need to define what we need to define big ball all right we need to define big ball and then again we'll pass it an x it will be past an x all right now what do i want to do well let's uh we're going to change the radius okay we're going to change the radius so what was the radius value that we had up here it was called m radius and so what we're going to do is inside this function we are going to change big we're going to change m radius well if i want to change it inside this function in this function i need to make it global m radius so now we're all talking about the same m radius now what do i want to do well i'm going to say if x dot checked now this here you could call it whatever you wanted to okay but if you call it x here you need to call it x here so i'm going to see is x checked if x checked is equal equal true what do i want to do that means i want a what i want a big ball and so what i will do then is i will say m radius is equal to m radius times 2. now why did i not just change m radius because i don't know m radius might have just have something might have happened outside so i just want to make it what it was before times two not just set it to a bigger number because if i just set it to a bigger number then when i come up here this m radius things that are based on that are just not going to work anymore i hope that makes sense so we want to make sure that everybody is using the same m radius so we're going to say m radius the new m radius is the old m radius times 2. all right and then what do i want to do i want to go if x dot checked is equal eq is equal equal false then what do i want to do if it is false i want to say m radius is equal to m radius divided by 2. now this is kind of a dangerous thing to do but what you got to see here is is that this is going to work because when it starts that's going to be unchecked and the first time you click it it checks it and therefore it is going to go twice as big and the next time you click it it is going to uncheck it and it's going to go back and so since this is just a toggle function this will actually work but you got to really be careful when you're doing things like this to make sure you're not going to you're not going to goof something up okay then what else do i need to do well now that i have m radius i need to actually make the ball a different size and that that i would do that by saying the marble right so let's make sure what the ball is called the ball is called marble up here so what i'm going to do now is say marble dot radio is equal to m radius which we just set to the right value there and then here we're going to do the same thing marble dot ray d s is equal to m radius so now i should be able to go in and just make it uh make it you know make everything work but you see the problem this is i guess this is what i was trying to say earlier that i didn't say very well and what that is is what if i just said marble radius is equal to you know something bigger okay the problem is down here where i'm doing things [Music] let's see where i am doing things i don't say oh here it is when i'm doing things like this if i change the size of the marble but i don't change m radius then this is operating based on an incorrect assumption of how big that marble is so hopefully that makes sense so let's run this let's run this and see what happens now okay so i have run let's run it all right and now let's make a big ball look at that boom we got the big ball and what i want you to see is even though i change the size of the ball it is still bouncing correctly all right so let's come over here and let's kill that or let me just show you one more time what do i not like about this i don't like how those are kind of jammed too close together there and so we need to do a little bit of formatting here and i'm going to show you some things that'll just make your life really easy if you know how to do this so kind of like between the radio after i create the radio button and then before i create the check box what i would really like to do is i would like to say scene dot append scene dot append and then what do i want to append i'm gonna append just some spaces like that and that will scoot that second it that will scoot the check box over to the right away from the radio so let's see if that works well what we did is we broke it so let's go in and see what let's see what we did wrong there so we'll kill this okay so what i do is i say i do the radio that's good and then i do oh okay scene dot append underscore to caption okay scene dot append to caption and that should scoot it over okay now we've got run and we've got big ball and big ball i can toggle run i can toggle i can toggle big ball as i am running all right so that is working good and it's looking much better i hope you agree so now we know how to do radio buttons and we know how to do check boxes and then we also know how to put some blank spaces in by doing scene dot append to caption now i'm going to show you one other one that you can do instead of putting blank spaces like if you put a slash okay that's for me the slash that is above the enter key make sure you're keeping the direction of your slash right slash n and then slash in like that what that and then i don't want the spaces there okay then what that will do is that will kill the program all right that will move it to a new line so that slash n takes you to the next line and then the slash end takes you to the next line and then i have a little uh a little uh space in there like that and it still works okay so that still works but in fact that was just for less illustration purposes i really want spaces in there between them okay so that is pretty good so we have done the uh we have done the uh the big ball and we've done the run radio now what i want to do is and i actually think i want to put this up at the top so i'm going to do this before the radio button but what i'm going to do here is what if we want to set the color of the ball okay so in other in order to set the color of the ball what i need to do is i need to create a button okay the button is different than the radio and it is different than the check box the button is a little button and when you click on that button something happens so i'm going to create a button and then what i want to do is i want to bind it to i want to bind it to a function ball color red and so what does this button do it changes the ball to red so i'm going to bind it to ball color red and then i need some text on the button i need some label on the button so text text is going to be equal to red and notice i make a string out of that not the variable red but the string red that's kind of important and then i want the color to be equal to the color dot black and so the text is going to be black and then the back ground is going to be equal to color dot red and so it's going to be a red button it's going to have black text on it the black text is going to say red and then when that is clicked it is going to call ball color red well if i'm going to call ball color red i better what i better define it so define ball color red and that's going to get past an x again okay and then we are going to say that uh in case this thing gets called what do i want to do well it's really kind of simple i just want to say marble dot color is equal to color dot red now this is something that you wouldn't really necessarily know this unless you tried it but this marble this kind of like marble method is global and so inside this function it knows what marble dot whatever it is these things you don't have to go in and try to pass them in it just they're sort of uh as built they're uh their their global so i can call this marble method directly from this marble.color method directly from uh inside of this function and so what that should do is that should turn the marble red now let's see the was the marble already red yeah the marble was already red well let's start with the marble white okay just so we can see something happening all right let's see what happens okay so here i've got the red button and then i can click red and it does turn red now clicking it again doesn't do anything because i'm like saying turn it red turn it red turn it red that's different than these buttons that sort of toggle you see these buttons sort of toggle but this button just does what you say and i hope that makes sense well what do you see you really want like a new line there and so let's come in here and let's uh let's put in a line break after let's put in a line break after that ball color red so what we would do there is we would do what we did down here which was scene dot append to caption scene dot append to caption and then what do we want to append we want to append the all uh backslash in backslash n like that now that should look a little better i do believe okay you got red and then down here you've got run okay now still what we need to do is we need to add the other colors that we might want to make and now what i'm going to do is i'm going to go ahead and back and make the marble start out red because i just had to change it to something else to make it look you know to see if it was actually working so what we're going to do is we're going to take this and we're going to copy it those two lines of code and then we're going to paste it and then we're going to paste it all right now this is red and so this one then is going to be green and then marble color would be color dot green okay and then we're going to want to bind this to color green like that and it's happy with that and then this will be labeled green and then the color the text color is still black and then we want to make it green little green like that okay now this would be red green this one would be blue and then you would want color dot blue and then you would want this to call ball color blue and then the text should be blue and then the background is equal to color dot a blue like that all right and then after you get all those three buttons across then you go to the new line so let's see if that works i don't think i made a mistake in there but i could have let me make sure that it's dead all right let's go okay look at that red green blue so let's make a big ball and then let's say red green blue boom look at that that is working great now i'm kind of debating whether i would really like a little space between these buttons but i kind of like the effect there that it's like a color bar okay and now look at this i can change these things in real time and i think this is just pretty amazing and i have got a stuck ball what happened did you see that okay let's make sure it doesn't happen again okay now i would have to go in and really check that for debugging but i think right as the ball was approaching the wall i changed its size and it sort of hopped over the barrier and because it hopped over the barrier then it kind of got stuck there because i changed the size of the ball right as it was coming up to the wall now this would be some fairly detailed uh debugging to i'm trying to make it happen again yeah i got it there but if you do it right as it bounces there it is okay if you click it right as it bounces then you sort of goof up the algorithm and i'm not going to worry about trying to uh trying to fix that you could go in and sort of see it's in those if statements you would need to be a little bit more careful in the if statements because when we wrote those if statements we were not anticipating that randomly the ball could change position i could change i could change size on us so that is probably what is happening there and you see these if statements get into these other parameters and those other parameters to fit depend on the radius and so you could end up throwing it into a little bit of a strange uh strange situation there okay so like the xmre is being compared here and so that depends on the ball radius so you could just randomly you could run into trouble and so we could think through that a little bit more but if we did then you would not learn all the other cool widgets so we are going to go ahead and we are going to define some other widgets so we have done the three colors red green blue we've done the radio button which turns the ball on and off and we have done the big ball check box okay now the other thing that you might want to do is you might want to instead of having something on or off or just toggled you might want to set a value and you do you set a value using a can you guess using a those of you guys who are in my ai class would probably be saying track bar track bar you would be wrong in opens or in opencv they're called uh track bars in v python they are called sliders okay and so on the slider we're going to bind to what do we want the slider to do well i want it to control the ball opacity so i will call the function ball opacity like that ball opacity and now if you want the slider bar to be up and down you would set vertical equal to true but i want it sideways so i would say vertical is equal to false because i don't want it vertical and then where do you want the slider bar to start at well i want the minimum value to be equal to zero and then i want the maximum value to be equal to one so i'm going to go from zero to one so because those are the parameters that the opacity goes through and then what value do i want to start at well when i create that ball it's solid and so i want to set i want to set this this uh this function to have that same value so i'm going to set it to 1 since that's what it was set at in the program and this will make it that it match and then i need to say the text is equal to uh ball uh opacity of the ball like that and so that should set up that slider bar but now what do we want to do when the slider bar is monkeyed with well what we will need to do is we will need to define our function ball opacity and then we'll pass the x again like that and then we will need to come over here and figure out what are we going to do well what we need to do is we need to get the opacity value and that is x dot value okay the x because that's what we passed it and then the value is going to read that value off of the slider and then we are going to put that into op all right now i'm not making op a global variable because it's just going to stay in this function what happens in this function stays in this function so we're just going to leave it here we're not going to make it a global variable but then what i want to do i want to make the marble.opacity equal to that op value like that and now it we should have a slider bar and as we slide it we should affect how the opacity of that marble looks all right let's see if that works and let's make sure okay well that's kind of interesting we do have a slider bar and i did definitely put it in the wrong spot i wanted it down below this but i must have put it above it but we'll clean that up let's make sure red green blue still work big ball still works now let's see if we can slide that opacity down wow look at that boom we got it now let's make it run okay so even as it is running we can make that ball more and more and more transparent until it's almost just disappeared and so you see we can just dial that in any way we like okay that is really cool i love that so let's kill it and let's put it in the right place this time so i wanted that to be after after all this other stuff so i'm going to get all of this here that we just did and i'm going to cut all right i'm going to do all this and i am going to cut and then i am going to come down after the big ball and i'm going to put it and i want it on the new line and so i'm going to do a scene dot append to caption and then i'm going to put the the backslash in backslash n and that needs to be in a quote single quote like that okay so that should put the slider bar at the bottom on a new line [Music] okay there it is so i'll say big ball okay that is working now one thing i notice is i think i made a little mistake here and that is where i came in and i said the text on the slider i don't think you can put text on a slider i or i've learned now that you can't put the text on the slider so what i will need to do is i will just need to make a label up here and that label is going to be a scene dot append to caption i think that is a scene dot append to caption i'm wanting to make sure that there is not no it's not that is for those special characters what i'm going to do is i'm just going to put a w t e x t write text a write text and that is going to be text equal and what this is going to be is choose your opacity how about choose ball opacity okay now after that and that was a really really silly place to put that so let me come over here let me cut it out of there and i want it yeah it probably would have worked there it probably would have worked there but we're going to put it up here just because a little more logical order and then we are going to go to a new line again okay so this will put the label this will put the new line in a blank space and this will be the slider itself and i think i want just a new line not a new line new line and this way it'll just go to the new line there won't be a blank line in there so let's see what happens okay so that looks good choose ball opacity and it looks like that is working okay blue green red is working we can still go change the color okay that looks good although i do think now that it does look crowded and so let's go back and let's put the extra slash in there if you know what i mean right there another backslash in and now that should look good but i'm not going to run it because we're going to move on we are going to move on to our next our next widget so we've done text and we've done radios and we've done check boxes and uh we have done sliders and so the next one that i want to show you is the next one that i want to show you is i want to show you how to do a drop down menu okay and so a drop down menu is pretty exciting so i'm going to say menu we want a menu and let's see let's say that the menu menu sets the ball speed so i'm going to say bind it to a function called speed why is it not happy because i haven't defined speed yet and then i got to give it a list of choices now when you give it choices you have to put it in an array and then the the choices need to be strings they need to be text values so my choices are going to be uh one my choi or one my choice will be two two your choice will be three your choice will be four your choice will be five like that so those are your choices okay and that's just it you get tell it what to bind and you tell it uh which what not band bind you tell it what to bind to and then you tell it what the the choices on the list need to be and so if we're going to call speed we better define speed and so speed is going to get x again and then we are going to come down here and now what we need to do is we're going to set a new variable my speed so we're going to make global variable my speed okay now if it's going to be global and it's used in the rest of the program we ought to give it a value up here and so sort of like where we said run is equal to 0 we need to say my speed is equal to one okay because we're going to use my speed down in the rest of the program and therefore we better give it a value to have before that before that drop down menu is selected and i think we've done enough of this i hope that really that really makes sense so the the program will have a value for my speed even if you don't come in here and that is very important or your program will crash the first time you try to use my speed okay so global my speed now what i want to say is if x dot c lected is equal to equal to 1 then what do i want equal equal to one then what do i want i want my speed to be equal to the number one okay now we want one we want two three four five so i'm just going to copy this and i'm going to come down here and then i'm going to say paste okay so now that's going to be for 2 that's going to be for 3. going to be for four and that's going to be for five and i put an extra goofy space in there okay so one makes one two will make two three will make three and then four will make four and then five will make five okay now we've got to somehow use that myspeed right if we're going to define it then we need to use it somehow and so where would be the best place to do it well i think i would like to do it here because like if if i multiply delta x that run is a one or a zero and then if it is running if it's a one now i need to multiply it by a speed because that'll like amplify it that'll make it go like it's like making delta x bigger which will make it run faster and so here i'm going to say times my speed and then times my speed again we made that a global variable so that should work like that all right let's try that okay so why is it not running because we didn't tell it to run okay and why do i not have oh there's the drop down menu okay what did i forget who's your friend slash n slash n that would have been a great place to do that but let's come down and make it a five okay and there you can see it's really going fast come down and make it a two it slows down okay that looks really good but we need to clean that up a little bit so we need to come up here and before we do the speed nonsense we need to put it on the next line or i think i'm going to instead of doing that i'm just going to put it up beside above the slider bar so i'm going to cut this whole thing and i'm going to put it above the slider bar and ball opacity is where we did that so i'm just going to put it here on that same line that we have those buttons on okay and i think this should be good and then it'll go to the new line let's try that okay now i don't like it oh no that's not good that's not the right place either i put it with the label i put it with the label so let's kill this nothing like a little trial and error on this stuff huh okay so let me cut it again but you see this now i'm getting this speed okay i need to get the menu with it i need to get all that so now i am going to copy all that cut all that would be more suitable okay and instead of putting it there with that choose ball opacity which is what it came after i want to do it uh after the check box okay after the check box that's where i do it and then what i will want to do is a scene dot append to caption and then i need to scoot it over a little bit so i'll put some blank spaces so the little drop down menu is over to the right a little bit i really think this is going to work this time okay i got my ball of opacity there i've made this a little bit too big right there so now here is my drop down menu and then i can come in and i can say to and then let's actually turn it on okay i can make it a one i can make it a four i can make it a five okay so that's looking really good right i like all this stuff i like everything about this okay now the one thing i don't like is now i see this needs some sort of designator for what this is so we need to put a label on it and then if we put a label on it i really do want it down below that so that it's not confusing so let's see if we can tweak that up a little bit better and so i want to put a label right before this and so uh what i can do here is i can do what was that called that was called a w text so i'm going to say w text and then what is the text that i want to put there choose ball speed okay and then i don't need this scene dot append here anymore right i don't need that so i'm going to cut that out but what i'm going to do is i'm going to put a new line so that the menu appears below the label and so in order to get the new line we would need the slash n slash n like that now i'm going to just look and see what that looks like boy we lost it all didn't we and the program crashed so we did something very bad w text oh i didn't do s oh text equal text equal at once did you guys catch that text equal can you tell i haven't written a v python program in a year okay all right that looks good so we've got ball opacity that's working but now this uh choose ball speed i needed on the new new line as well so i need to add another you know slash in slash in above the menu all right so i'll grab this scene dot append and then we need that before the we need that before the w text like that and guys i'm kind of making mistakes the thing is is that if i am really coding and i'm really doing something i really focus and i concentrate and i make sure i don't do the just trial and error things sometimes in making these videos i just deliberately am not real careful so that you sort of understand better how to do debugging and troubleshooting and so i kind of like deliberately let these errors in there to sort of see you how to show you how to think through these things but really if you're coding you do need to be as careful careful as you possibly can be okay so i've got choose ball speed now if if you're not running changing the ball speed isn't going to do anything so let's go ahead and run and then let's put it on a four okay and then let's choose a ball opacity of less let's go to the big green ball okay make the pot opacity less all right guys how do you like these sliders man how do you like these widgets i think they are just really cool you know you could even imagine like on the clock on the clock program uh i was thinking about doing this project or showing you the widgets with the clock but i just couldn't think of how to easily manipulate things on the clock is to show all the features of widgets as well as i could on the uh on the uh bouncing box here but i think things that you could do would be maybe you could turn an alarm on or off maybe you could you know be able to set when you want the alarm to be like set the alarm time and then you could turn the alarm on and off you could do things associated with that now since the clock uses the system time since the clock uses the system time you it really wouldn't make too much sense to use a slider bar to set the time because you're already grabbing the time off the off the system clock but what i will give you i will give you a homework and what your homework is going to be is your homework is going to be to take your clock and add some of these uh some of these widgets to it to make your clock customizable you could set the you know you could you could set different things like you could set the colors of different parts of your clock you could set like the length of the hour the length of the minute hand there are things that you could do and so what your homework is is to use these widgets to customize the clock that you've been working on in this series of lessons okay guys this has been really neat and i hope you guys have enjoyed this uh this v python series i've really had a lot of fun with it but what we're going to do now is we're going to change gears just a little bit we're going to continue with these series but what i want to do now is i want to actually hook the python up to an arduino and then start having python talk to arduino and arduino talk to python and start having this sort of melding of these virtual worlds with the real world of the arduino and i think there's just some really exciting and really cool things that we will be able to do there probably what i'm likely going to do is as we go to the next lesson instead of having that next lesson called python 3d graphics tutorial 22 probably what i'm going to call it is you know python and arduino lesson one and then it will pick up where this lesson left off does that make sense and that way if someone just wants to learn how to make python and arduino work together they could just jump in at that point and so it's definitely going to continue with the orange shirt series it's going to be this series of lessons but i'm just going to give a slightly different tag to it so that people who are just interested in that part could indeed join okay guys man i really am having a lot of fun when you do the homework make sure that you post your homework to uh youtube upload it and then put a in the links down below a comment to your solution to your youtube posting and then on your youtube posting make sure that you reference back that you link back in your description to this video so anybody that sees your video would have context of kind of like what you're uh what you're doing and what you're working on okay guys i hope you're having as much fun taking these lessons as i am making them i am just really loving this if you like the video give us a thumbs up if you've not subscribed to the channel already make sure you subscribe when you subscribe make sure you ring that bell and then share this with other people because we need more people doing productive things like coding and fewer people sitting around watching silly cat videos paul mcquarter from toptechboy.com i will talk to you guys later
Info
Channel: Paul McWhorter
Views: 1,728
Rating: undefined out of 5
Keywords:
Id: PJKBrPkcoMo
Channel Id: undefined
Length: 58min 57sec (3537 seconds)
Published: Wed Dec 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.