Add Input Boxes For Our CRM Tool - Python Tkinter GUI Tutorial #30

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys John elder here from Kota me.com and in this video we're going to start to build out the text boxes for our CRM project with Python and Kenter in the last video we built out our table in this video we're gonna modify the table a little bit but mostly we're gonna focus on building out the text boxes so that we can enter data into the database but before we get started if you like this video want to see more like it be sure to smash the like button below subscribe to the channel and check out Cody Meachem where I have dozens of courses with hundreds of videos that teach you to code use coupon code youtube to get $20 off membership that's all my courses videos and books for one-time fee just $27 which is insanely cheap alright like I said in the last video we created a table and first I want to mention that we had to put all of this stuff all on one line and I was going to show you in this video a real easy way to get around that you could just use back slashes after each one to put these on a different line so that's just a handy little thing I was gonna show you that in the last video but we kind of ran out of time so that's much easier to read so what we want to do now is modify this either get rid of it completely and you can see I've written some code to do that here to drop the table and so it's just my cursor to execute drop table customers that will delete the table right so we may or may not want to do that we could also alter this table to add more fields because you know we have first-name lastname zip code and price paid but if we go back over to the website there's a whole bunch of other stuff we want to keep track of so we need fields for that in our table so I'm actually not gonna drop the table what I'm gonna do is just alter the table and I'll show you how to do that right now so let's just go alter table and I'm just gonna paste this code in so what we want here is my cursor execute and then the command the sequel command is alter table and then we want to alter the customers table and what we want to do how we want to alter it is we want to add stuff and so we add stuff and then we just create a tuple right opening/closing and just like up here we just put one on each line what we want so we've got email address wanna address Tuesday city state country phone payment method and discount code and you can see mostly these are all farc are of various links so that's pretty simple now another thing I want to do is we've created this table every time every time we run this code we don't want this to keep trying to create a table that will throw an error so to get around that we can either comment this out or we could just go create table if not exists plural so now it'll check it's a basic if statement it'll say hey does the table exist if it doesn't create it if it does just ignore it so alright that looks good okay so if we save this and run it we should add all these things to our table and then down here from last video this will print it out on the screen to make sure we did everything right so let's save this and let's run it again and when we do our box pops up we can close it and then BOOM here is our table so we have first name last name zip code price paid user ID email address 1 address 2 city state country phone payment method and discount code okay so far so good now can well first we need to comment this out so I'm gonna use three single quotation marks to comment and then three more two in the comment because every time we don't want to alter the table every time we run our could but I want to keep this in here because this you can get this code on my github page if you want to actually look at it so I'll leave it comment it out and same thing down here we don't want to show this table we can just comment that out and we don't want we don't want this either there we go okay so now let's start to build out our GUI our graphical user interface because right now we just have an empty box right so first thing we want to do is create a label and this is just gonna be the title label and it's just gonna set this equal to label and it's gonna be in our root program and the text is gonna be what Co to me customer database I don't know right and then we want the font to equal want but let's make it helvete Helvetica haze blow that yeah and we want the font size to be I don't know 16 or so and that should be good now where do we want to put this score label dot we want to grid this because we're gonna have to make this sort of complicated we can't just pack this stuff onto the screen so let's put this at row equals zero column equals zero and for now let's go column span equal to and we want to give this a pad Y of 10 and we'll see what that is just a second so let's save this and run it real quick all right so we have this customer coded me customer database it's got some padding here on the side okay doesn't look great now but we're gonna add columns underneath it and it'll look better when we do that so okay so far so good so now we want to start building out the boxes for our text fields so that we can actually enter in data from our customers into the database so we're gonna need a field for each one of these things right and each one of these things so a bunch of them they're returning of thirteen or fourteen of them so let's just start out making them so let's go first underscore name underscore or label and set that equal to a label in our root program you want the text to equal what first-name we want this to want to grid this and so we want to put this on row equals one column equals zero and that's fine so I'm just gonna copy this and let's do another one for last name instead of it saying first name we want this to say hell ass name and we want this to be in a row to same column though now I'm just gonna go ahead and pause this and write in the rest of these so you don't have to watch me type over and over again because that's pretty boring okay so we've got first name last name address 1 address 2 city state zip code country phone email username payment method discount code and the price paid so let's go ahead and save this give it a quick run to see if there's any errors ok so we see this and they're all kind of centered in this column and that is not at least to me that doesn't look very good so let's change this around a little bit we can give it a sticky to sticky it to the left side and remember sticky in labels is north south east and west north south east west right so if we want this all on the west side we can give it a sticky of W W and we also kind of want to give it a little bit of padding off the side because it's gonna smoosh it right up see like this right here it's right up against the edge we want to put it over so I'll give it a pad X of 10 go ahead and close this code again and it's like last time I'm gonna pause the video and do this you don't have to watch me type all this stuff out okay so what we did here is we gave each one a sticky of W and a pad X of 10 so let's save this and run it okay so that's looking a little bit better everything lines up here alright looking good so now we want to add entry boxes text boxes right and with kinter those text boxes are called entry boxes all right so we can just create entry boxes and I'm going to use the same naming right for each of these but instead of calling them first name underscore label I'm gonna call first name underscore box right and set that equal to entry and we want it in our root directory or a root program now in the up here we just dot gridded each of these on the same line but we can't do that here because later on we want to have a button that if we click the button it'll clear all the fields and we can't do that for some reason if we also have a grid on there it messes it up so we have to do this on a separate line so let's go grid and let's see we want this to be in row equals one and column equals one right and you just want to go through here and do this for each of these right same thing so again I'm not gonna make you watch me type all of this stuff okay so what I did here is I just went last name and then we just put it down a row same column and I gave it a pad Y of five pad Y is up and down so they're not smooshed all together so Row 2 Row 3 Row 4 for each one city state zip code go ahead and save this and run it and we see it's starting to our thing is no longer big enough so let's fix that real quick head back to the very top here and instead of 400 by 400 let's go I don't know 400 by 600 see how that looks save it run it okay that's a little better and alright so we've got we can type stuff and tab and everything is looking good all right so now we need a couple of buttons here we need a button to actually submit the stuff to our database and we need a button to clear these each of these so let's do that real quick head on back down and let's go create buttons and let's go add underscore customer underscore button and that's a button and it's in route and the text is gonna say what add customer to database and we'll have a command that fires a function to actually add this we'll do that in a bit but for now let's go add your score button dot grid and let's see where are we here so we're on row 13 for the price paid so our next row will be 14 column equals one and let's give this let's give this a pad X of 10 and a pad Y of 10 let's go ahead and save this and run it to see how that looks okay so it's in this column and I don't love that so much so let's change that instead of column 1 let's put it in column 0 let's run this okay so that's right they're looking good now let's put another button underneath here and we'll use that to you know clear this stuff so let's call this clear underscore fields your score button and it's a button in root and we want the text to be what clear fields maybe and we'll give this a command in just a second let's go clear fields button grid and we want this in row 14 column 1 and we don't have to give this Pat X or Y I will sort of inherit from the button next to it so let's save this and run it see what that looks like okay at customer clear fields cool so let's do this clear fields button real quick knock that out it should be pretty easy so let's come down here and our clear fields let's give this a command of what clear underscore fields that button this function clear fields will fire so now we need to create that function so let's kind of go up to the top I like to create my functions towards the top of my program so let's go create let's go clear text fields and we want to define their fields and let's just return this for now so what we want to do here is actually delete all of the things in each of those boxes so we just have to go first underscore name underscore box we just fire the dot delete function and then for entry boxes if you remember back to the video we did on entry boxes like a year ago or whatever we just go 0 and then end so I'm gonna just just gonna save this and run it to make sure that works before we do all the other buttons so I can add a bunch of stuff and I I click there boom it disappears alright so now we just have to go through and do the same thing for all of our boxes and again I'm not gonna make you watch me type all those stuff this stuff and I'm just gonna paste it so last name address sectors to city state zip code it's such Russ let's go ahead and save this and run it so let's give each of these things some stuff and if I click this boom they all disappear except for these three the last three are wonky so let's see what did i do there oh you don't have a username all right so payment method box discount code box in price paid box that should work let's save this and run it again just to make sure an extra box listed all right clear fields boom all clear all right so now the only thing to do is create this added customer to database button and this video is getting a little bit long but I think we can do it real quick here so let's go down to our button here and our add customer button let's give this a command and what do we want to call this it really doesn't matter let's just call it add customer all right so now we need to create that functions go back up to the top here and where do we want to put this let's put this right underneath this guy let's go submit customer to database all right so we want to define add customer all right so I'm gonna break this into a couple of things so I'm gonna go sequel command equals something and let's go values equals something now what we want to do is just go my underscore cursor dot execute right and we just want to pass in each of these things so let's go sequel command-comma values right and once we do that we need to commit the changes to the database I always do that with databases databases are almost always a two-step process you do a thing and then you commit the thing so you kind of shove the stuff into the database and then you save it basically all right so to commit we just call my DB dot commit okay and this my DB if you remember is the name of our database that we created up here our database connection so all right so that will commit the change so now we just need to add the values in the sequel command and the sequel command is we want to insert into our customers tumors and type customers table all right what do we want to insert into stuff right we'll talk about that in just a second and then we want to inch insert the values of other stuff right so what are these two things well this one right here is going to be the names of all of our columns right so first-name lastname zip code so we're designating what columns we want to put stuff in and the values that's going to be the actual stuff that we type into the program right so we've got let's let's count them up here we've got 1 2 3 4 5 6 7 8 9 10 11 12 13 we've got 14 things that we want to add to the database right so we need to put 14 values but we don't want to put the values there we just want to put a placeholder will designate the values down here so it's easier to read so placeholders are just % s okay so we need 14 of those so I'm just gonna copy and paste so 1 2 3 4 5 6 7 8 9 10 11 12 13 14 right and 4 here I'm just gonna copy these I've got it written down already these are just the names of the columns in our table right so we're looking at first-name lastname zip code that corresponds to this first name this last name this zip code this price paid right okay so that's sequel command we're saying put some values 14 of them into these 14 columns right so what are the actual values we want to add that's what we do on this line right here and what this is these are just these entry boxes right so we're looking at that's actually not quotation marks we're gonna create a double with each of these items so it's gonna be first first underscore name box dot yet because remember with entry boxes we get whatever's int it entered into them you remember back to the entry box video we did months ago that's how you do that and then so then last underscore name box dot get now these need to completely line up to these so first name first name last name last name zip code zip code underscore box dot get right they have to completely lend up or else it's gonna you're gonna get errors it's not gonna work so I'm going to just copy and paste all these in and I'm copying and pasting a lot of stuff in this video because it's a long video and there's a lot of typing you can get this code I'll show you in a minute on my github page it's github.com slash flat planet I think let's just look at that real quick right now before we move on so it's github.com and let's see my repositories so good how github.com for slush flat planet no I don't think the world's flat I just find hilarious some people do find this intro to kinter youtube course and then go down to crm oh I haven't actually entered it yet after this video I'll push it up there and you'll see it you can click on it and see the code but for now first name last name first name last name zip code zip code just do a quick spot check to make sure price paid price paid email email address 1 address 1 to address to city state country phone city state country phone and then finally payment method and discount code payment method and discount code okay so I think we're good there now the last thing we want to do is just run this function so after we click the box to enter the stuff we want to you know clear all the boxes so just below here I'll just clear the fields and let's go clear the fields all right so save this alright let's give this a run almost certainly I created an error so far so good let's fill this out real quick let's go John elder 10 West Elm I used to live in Chicago what was my I think it was 1508 maybe no that's right Chicago Illinois and Zucca was six oh six one zero and us a phone number one one two two two three three three three email address John go to me.com let's see you I used a visa I used the discount code youtube' and the price I paid was $27 all right so let's click this button and see oh I did not erase which means we have an error lets you up what do we get during the handling exception occurred couple index out of range line 83 so all right what did we do right here so let's count we've got one two three or five six seven eight nine oops nine was state I think right I think in 1112 there's 13 fields and what do we do 1 2 3 4 5 6 7 8 9 10 11 12 13 14 I put 14 for some reason all right so we only need 13 so let's save this head back over here run this again alright John elder hey alright so add customer oh right disappeared so hopefully we got no error all right but did it actually add it to the database right so let's come down here real quick and just add right some quick code to see so let's just query the database real quick let's go my underscore cursor dot execute and we want to select everything from customers and then let's say result equals my cursor fetch all and let's go for X and result print X okay so we're gonna pull out everything from the database we're gonna loop through it print it on the screen basically right so let's run this again program opens we close it and boom it prints out everything in there John elder a $27 our user ID is one all right looks like it worked so fairly simple I mean it seemed like a lot of stuff and again you can check my github for all of this code but I copied and pasted a lot of stuff but but not too bad starting to look like a program right and we can enter stuff into these things we can clear it we can add stuff to the database pretty cool so we're making some progress in the next video we'll kind of create a function to where we can look in the database instead of having to look at the command prompt like we just did now I will actually do it graphically you'll start to look at that in the next video so that's all for this video if you liked it be sure to smash the like button below subscribe to the channel and check out cutting me calm or you can use coupon code youtube $20 off membership is just $27 to access all my courses hundreds of videos and the PDFs of all my best-selling coding books join over 60,000 students learning to code just like you my name is John elder Francona me calm and we'll see you in the next video
Info
Channel: Codemy.com
Views: 19,012
Rating: undefined out of 5
Keywords: tkinter entry widget, tkinter input fields, tkinter entry fields, tkinter input boxes, crm, python crm, python tkinter crm, crm with tkinter, kinter, python, tkinter, python tkinter, tkinter python, python gui, tkinter gui, gui python, how to python tkinter, tkinter mysql, mysql tkinter, using mysql with tkinter, mysql python tkinter, tkinter mysql python, tkinter database, alter table, mysql alter table, mysql python alter table, python tutorial, mysql python tutorial
Id: ZuEbBvUPGzE
Channel Id: undefined
Length: 25min 11sec (1511 seconds)
Published: Wed Nov 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.