Creating Input Fields With TKinter - Python Tkinter GUI Tutorial #4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys my name is John elder from Konami comm and in this video I'm going to show you how to do input boxes with kinter and Python all right what's going on guys in the last video we learned how to do buttons in this video we're going to talk about input boxes how to input data into your program but before we get started if you like this video and want to see more like it be sure to smash the like button below subscribe to the channel and be sure to check out Kodi me comm where I have dozens of courses with hundreds of videos that teach you to code use coupon code youtube to get $22 off membership so that's all my courses videos and books for a one-time fee it just $27 which is insanely cheap so I've got the program we did yesterday it's going to close this and let's just run this real quick to refresh our memories and so just pull this over so we get this little button if we click it it puts some text up on the screen so that's kind of cool but we want to expand on this and put a little like input box sort of like a webform you know we're a box you can type stuff into and then we want to do stuff with whatever we type into that thing so that's what we're gonna do in this video so let's go ahead and close this pull our text our stuff back up and to do an input box in kinter we use not an input widget which is what you would think that we call it but it's called an entry widget we're entering data right so let's go up here to file and let's save this as entry hi so we want to create a entry widget right so I'm just going to call this ee4 entry so e equals entry this is the entry widget and we want this to be in route now there's a whole bunch of other stuff we can put in here parameters and things and we'll talk about that in just a minute so instead of doing that let's just eat pack this guy in here and go ahead and save this so this is entry PI so I'm gonna pull up my thing here and let's run entry remember this is just a the terminal that I use you can use any terminal I'm in c4 slash GUI which is the directory where I'm saving all of these files for this course okay so pull this over and we see you know we've got this box we can type stuff in if we click here it doesn't do anything this this is from the last episode of last video we did so okay we've got an input box that's kind of cool before we go on let's talk about some of these parameters so we can't immediately change the size of this thing so we can go with equals we've seen with before I think and I'm just going to call this 50 so if we save this come back and run it you can see now our input box is quite a bit bigger all right so whatever size you want you could do that pretty simple let's see what else we can do we can change the color in the same way that we changed the button color remember F G and B G so if we want to go B G equals you know I don't know blue right save this come back here and hit reload now the box is blue and the stuff we type is black it's kind of ugly but you know whatever floats your boat we can also do foreground color and let's just change this to white instance there we go save this run it and we get the same ugly blue but now the text inside is white okay that's kind of cool I guess still a little goofy so let's get rid of that because that is just ugly we can also change the border width and so let's say I don't know five so if we save this and run it that's that big enough can you tell so you see the border has sort of a raised kind of thing to it I don't know why you would want to do that but if you did you could do that that's kind of cool so those are sort of the there's other parameters you can play around with and I'm not gonna really talk about them because they're not as cool all right but I guess you did a google if you're really interested but now we want to talk about alright what what can we do with text that's been entered into this form or into this input box and to this entry widget how do we actually do stuff with it well what we want to do is we can pull an e dot get and this get function gets whatever you've typed into that that thing so let's let's use this with our button so we've got this button it says click me instead let's change this to enter your name right and we want when this runs we want this my click function to fire so we've got the command right here command equals my click and now so when we click the button it'll execute so what do we want to happen when we click the button well let's go let's just change this my label instead of the text let's just type in that e dot get function okay so let's save this and run it and see if that works this over all right enter your name John boom John right so it's kind of cool now we can do sort of pythonic things with this if we want if we want to get crazy we can type in you know hello and then a plus sign concatenated in this is just pure Python this is not a kinder thing right we know how to concatenate you know smush two things together with Python so we do that so let's run this somebody is texting me like crazy so type in John hello John right so that's kind of cool we can also you're sort of looking at this this area right here is getting a little crazy right so right up here or really anywhere and set our function if we want we can say we can call a Hello variable right and we can say hello equals then the text hello and then we can concatenate e dot get just like that and then down here we really talked with us about this in the past but you can type in variables for your text fields as long as they're not let's see in quotation marks if you put them in equation marks it's just a string and it's going to treat it as a text string if you do like this it's a variable so now if we save this and run it see enter your name John elder get fancy let's do last name hello John elder right and if we keep doing this cool so pretty simple pretty straightforward that is how you do that now one last little thing that I didn't talk about we can go e dot insert and then now we want to give this an index number zero we need to talk about that there's only one there's only one box it's the zero with box and we can now give this a default value we can say enter your name right so we save this what this will do is this will put some default text inside of the text box right so you know a lot of times if you go to like a webform it'll say you know email inside the little box where you're supposed to type in your email or whatever it'll say username inside the box if you want to do something like that run this and then here it says enter your name right so then you would want to do that hello John so pretty pretty simple pretty straightforward pretty easy as everything has been so far in tkinter so now all right we can create a program we can have input boxes so we can enter data in we can click a button we can now do stuff with that you know programmatically behind the scenes we can then output based on what we typed in so we've got really the basis the fundamentals of almost any program like what does any program do except for taking data do stuff with it and then output it and here we have everything you need to know to do that with kinter and a graphical user interface using Python so it's very very simple very straightforward is less than 20 lines of code and we've got a fully functioning program that actually does something now it does something stupid it just enters a name on to the screen but hey you know you can take just this and really make any kind of program you want right say you want to create a stock quote program well enter the stock quote right we could just change this to enter your stock quote right we save it run it again enter your stock quotes so if I type in you know Facebook and then click the button it says hello Facebook but how easy would it be programmatically behind the scenes to instead of just print hello Facebook on the screen to take that Facebook stock quote connect to a third party API get the stock quote bring it back and put it put the current stock price on the screen it'd be pretty simple to do that in fact we're gonna start doing things like that in the next few videos we'll play around with this that's really really cool and just so just that easy to create really cool programs with this so that's all for this video if you liked it won't see more like it be sure to smash the like button below subscribe to the channel and check out coding me comm where you can use coupon code youtube to get $22 off membership so you pay just $27 to access all of my courses hundreds of videos and the PDF versions of all my best-selling coding books join over 50,000 students learning it to code just like you my name is John elder from Cody me calm and we'll see in the next video
Info
Channel: Codemy.com
Views: 174,006
Rating: undefined out of 5
Keywords: input fields with tKinter, entry widget tkinter, tkinter entry widget, tkinter input field, python, tkinter, gui, python tkinter, tkinter python, python gui, tkinter gui, gui python, graphical user interfaces python, tkinter grid system, grid system tkinter, python grid system, build graphical user interfaces with python, how to build graphical user interfaces with python, how to python tkinter
Id: 7A_csP9drJw
Channel Id: undefined
Length: 10min 26sec (626 seconds)
Published: Wed Jan 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.