 Hey everyone welcome back to some more Python programming tutorials We're looking at the end-py screen module in the last video. We were actually checking out how we can set up this Next active form variable within our form object or parent app class You know our app object that's kind of managing the forms and the screens that we see on our screen and Now that we've actually gotten our program to be able to close Properly we can move on we can do some cool stuff Now we're finally gonna actually add widgets or at least start to learn a little bit more about them So I'm gonna save my script as zero five now and let's do Let's I don't know. Let's as usual. Let's refer the documentation to see what we can do. I Remember reading way back in the create function I know it was it was talking about that as kind of the initializer or the forms constructor By default it does nothing, but we can override it and pretty much It's the best place to set up the widgets on a form So expect this method to be full of self dot add method calls Now that's what we're gonna be doing in the form create function We're gonna actually add those self dot method self dot add. Sorry method calls So that's what we'll call and we'll add some widgets now I'm kind of curious if it gives us any examples that I can I can show you But if not, we'll just move on to widgets and their basic features. So, okay Let's do some reading before we dive in Widgets are created by passing their class as the first argument of a forms add method The remaining arguments are gonna be passed the widgets on constructor and these control things such as size position name and initial values Cool. So let's try it out. I'll hop over to my code here and in our create function We can finally get rid of this pass keyword and actually do something cool here self dot add is the function that's going to create a new widget So we need the widget name This function is going to take what widget it is and in this case for learning purposes I'll tell you that we can use title Text notice that the t is capitalized in title and the t is capitalized in text for the first t in both of those words and It is going to need some other arguments, right? The remaining arguments are passed to the widgets on constructor Their class is the first argument. So that's why we pass in title text and The second the remaining arguments are going to be given in. I wonder if we can run it without it without any optional variables or arguments and Yeah, so now we've got this little thing here no name It says and it is a text box. We can type in text here sweet Got some got some interaction. Now. We can actually do something with our program Now if I press the arrow keys to kind of navigate and move over to the okay button I can hit enter and get out of our program So let's look at more of those arguments and stuff that we can add to it The constructor arguments name you should probably give each widget a name which is a string of force We're appropriate it will be used as the label of the widget and we saw that in our code, right? No name over here was probably set by default, but if we did supply a name name can equal Let's see First name and Then we're good Now if I run this you can see first name John. It's got a value over there sweet It's interesting though if you didn't want this to be displayed No name is like it said well. It showed us before by default, but if we try to set an empty string Whoa, we get an error That's so that's something that I kind of wanted to show you and point out to you However, if you use a space character you can kind of hide it so now you just have an Empty text box just floating out in space I Use control you which is a command line shortcut to delete all that text real quickly in case you wanted to know and So sweet all move our first name Back over there and let's see what else have we got here rel x and well y these are positions of the widget on the form They're controlled by relative x and relative y integers Normally you don't have to specify them and in this case the form will do its best to decide where to put them You can specify only one or the other if you choose you don't usually need to specify rel x honestly If you do give a negative value for rel x or well y the widget will try to be positioned to the bottom right hand side of The form and of the screen if the form is resized and pi screen will try and do its best to keep the widget in place nice There are other arguments for width height maximum width and height and values even okay, so we can supply a default value so I'll say First name value can equal Joe If I run this code. Hey now Joe is filled in there, but my name is John not Joe Values plural where a widget offers the user a selection from a list of values there can these can be specified here It's the initial setting of the values attributes. Oh, there are things like editable that determine whether or not We can actually edit the widget Normally it's true hidden whether with it widget is visible or not, huh? So I mean I can just set this not display with hidden equals true I run this huh Really? I'm not I don't I don't seem to be getting that that work Nope Doesn't look like it. Okay. Am I entering the wrong way? Even if hidden were false that would mean that it would be visible. Yeah, it's still visible Okay So there we go a little bit more learning for you guys there Maybe that one doesn't have as much functionality as we were hoping for color and label color. That's pretty cool We'll get into that more Scroll exit slow scroll and exit left and exit right or at least other options for it These affect the way that user interacts with multi-line widgets so we're gonna get into multi-line widgets really really soon of course because there are a lot more to learn about them and but for now you'll know that that argument does exist and Display update you can read about these if you'd like There are functions It looks like if you were to subclass a value or subclass a widget like a title text widget And you can actually subclass and kind of derive this function when the value is edited like once you've changed any portion of The text box you can know what what's going on and what's happening so that's kind of a cool way to do it and Of course you can override this function for your own use Same thing happens when cursor moved whenever you kind of go to a different position in the text box or anything else Edit is what allows you to interact with the widget kind of works like edit with the form and Set rel y and rel x are kind of similar things That we read about earlier Titled widgets those are the things that we're actually looking at right now because of course we have title text You can see that we've got Well, it explains here that many widgets exist in two forms one with a label and one without So the one with the label in this case is what we're looking at first name or this name argument acts as our label if the label is particularly long when it's kind of a Displaying it the label may be put on its own line, so I've seen a few examples of this like if I entered date of birth It might be a little long and you'll notice that date of birth is way up there and My input is way down here Some people might not like that So there are these options here that explains use two lines if either true or false override what the widget would otherwise to choose field width How wide should the entry part of the widget be? You can determine like You'll notice if I actually typed a lot of text in here It's gonna start to scroll a little bit So it can you can determine how wide should the thing be? in your display and This begin entry at is kind of an interesting variable because you can determine at what columns with the entry part of the widget begin By default it's 16, which is why all these characters date of birth in this label is too far And it's pushing it are it's pushing our input down a line if we had tried it like See what is it called begin entry at yeah begin entry at equals let's say 25 Now you'll notice 05 My cursor is way over here and that's where my entry begins So now we're not being pushed over on a new line by our date of birth label Cool Internally entitled widgets are usually a text box and whatever other kind of widget is required You can access the separate widgets if you need to you normally don't through the label widget and entry widget attributes Okay, so we can access these things with like a dot selector in our code However, you may never need to since the value and values attributes of the combined widget should work as expected Now there is a little bit of functionality for creating your own widgets You just have to subclass the widget class and you can calculate the area you can add lines make attributes and Resize this stuff. I'm not going to go into too much depth about that right now at least for this video I want to show you the very very basic introduction of a widget and kind of the arguments you can give it and pass to it Reminder hidden equals false or hidden equals true isn't working the way we expected note the interesting functionality of Multiple lines and if your label is too long or where you can begin your entry at a column that sort of stuff and Title text is just one of the many widgets that we can use I just want to use it as a gateway to teach you the constructor arguments and what more you can do with them So cool. I know this is probably a long video and I was just kind of guiding through the API reference But that's what a lot of this stuff is it's kind of exploring and seeing what you can do with it So thank you guys for watching. I hope you enjoyed this I'm certain we'll get into more cool stuff as we get further and further along in the series But it's his building blocks man. These are these are baby steps All right. Thank you again guys. I'll see you in the next tutorial