Python - How to Create Multiple Window Frames with TKinter ( The easiest way )

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey what's up guys in this video we're going to teach you how to switch frames in python using tkinter so this is a small example that i created so you can see how this works this is page number one if i click the enter button it takes me to page two and if i click the enter button here it takes me to page three and if i click the enter button again it takes me back to page one so you can bounce around between pages you don't necessarily have to go from page one to page two to page three you can go from like page one to page ten for example this is very useful if you want to create a project that's more than one page for example i created an atm machine i had the user enter their username and password in one page and if they entered it correctly then i let them into the atm machine there they were able to access more pages like the account balance page withdrawal page and deposit page not only is this useful but it's actually very easy to use especially with the way that i'm going to teach you in this video so let's go ahead and get started hey what's up guys in this video we're going to teach you how to switch frames in python using tkinter let's get started first thing we want to do is import decanter let's create an instance of this module and it's calling the main loop method let's create a frame now let's call it frame one and we want this to be in our window let's give it some color i'm gonna make it red all right let's place this in the window we're going to use the grid method and i'm going to place this in row 0 column 0 and i'm also going to give it a sticky and we're going to set this equal to north south east west and that's because we want this frame to basically mold into the size of the window let's run this let's expand this and notice that our frame isn't showing up and that's because we basically have to give it permission to show up on the window so we're going to use two methods for this one is called row configure this takes two parameters first one is zero and the next one is weight we're going to set that equal to one and the next method is column configure this takes in the same parameters so these two are going to make sure that when we expand the window our frame expands along with the window let's run it again now when we click on this we're able to see the frame but notice that we had to click on this button in order for us to see the window well we want that to happen automatically so we're going to use another method here this one is called state and we're going to include zoomed in there so when we run it again our window expands to its full size all right so we can get rid of this red here i was just using that so you can see what was happening now let's create a few more frames so this is frame two and this is going to be frame three and now we're going to use a for loop to place these on the window all at the same time and here we have to add the name of each frame and we're going to change this to frame so now when we run the project it's going to place all of these frames in our window right on top of each other because notice that we place them in the same location so they're all in row 0 column 0. so when this loop is done looping frame three is the one that's going to pop up on the screen but that's not necessarily the one that we want to see when we run the project so we have to create a function and we have to tell it which frame we want to display on the screen so let's create that function up here let's call it show frame this is going to take an argument frame and this is the frame that we're going to pass on to this function and this is the frame that we want to display on the screen so we're going to use tk rays for this let's make a function call to this down here and let's pass in frame number one so that's the one that we're going to see when we run the project if we run it right now we won't be able to see anything because none of the frames have any code in them so let's add some code to each one of the frames so this is going to be frame one code and let's give this frame a title we're gonna use a label for this we wanted to say this is frame one and let's give it some color as well let's make this one red i'm gonna give this a fill i'm gonna set this equal to x i just give it a button as well and when the user clicks on this button let's send them over to another frame so we're going to use the show frame function here let's send them over to frame two and let's copy and paste this so we're gonna do this for frame two and frame three as well let's make this one yellow and let's send over the user to frame number three when you click on this button so let's do this again for frame three i'm gonna make this one green and let's send the user back to frame one when they click on this particular button let me make this a little bit smaller for you guys just in case you can't see everything that's on the screen all right that's a little bit better let's separate this and let's go ahead and run this all right so this is frame one when i click on this button it's gonna take me to frame two and when i click on this it's gonna take me to frame three and when i click it again it's going to take me to frame one so that's how it works pretty simple this is the easiest way that i found to do this so far i've actually made a tutorial before on how to create an atm machine and i use a different method but i thought it was a lot more difficult to use that particular method so maybe some people might look at that and be like man i'm not gonna do all that that's way too much work and i mean i understand but that's why i made this video so if you guys want to learn how to switch frames you could use this code and it's a lot more easy to understand but now let me show you a real example of how i use this code so you can see how you can use this and this is actually the other way that i know how to do this but as you can see it looks a little bit complicated but that's probably because we're using classes so that's probably what makes it look a little bit more complicated but really it's the same thing so let me go ahead and run this and this is a little atm machine if you guys want to learn how to make this i'll leave a link in the description to the playlist for this tutorial so if i enter the correct password it's going to take me over to this frame so this is a completely different frame than the one that you just seen and this is gonna take me to another frame and this is gonna after i enter an amount it's gonna take me back to this frame and then we have this frame as well this is the deposit frame and then we have the balance frame and this takes us back to the beginning so yeah that's the purpose of this tutorial to teach you how to switch between frames or pages whatever you feel like calling it and yeah that's gonna be it for this video thanks for watching guys [Music]
Info
Channel: Web Dev Tutorials
Views: 67,681
Rating: undefined out of 5
Keywords: how to switch frames in python, multiple window frames python, multiple frames python, how to switch frames python, switching frames python, switch frames python, window frames python, switching frames tkinter, tkinter multiple window frames, tkinter python switching frames, how to switch frames in tkinter
Id: MKgDQjZwI2o
Channel Id: undefined
Length: 10min 0sec (600 seconds)
Published: Thu Aug 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.