Python - How to Create Multiple Window Frames with TKinter ( The easiest way )
HTML-код
- Опубликовано: 21 июл 2024
- In this video we show you how to switch frames in Python using TKinter. There are several ways to do this but this is by far the easiest way I have found so far.
GitHub Repository ( Don't forget to star !):
github.com/miguelznunez/Switc...
Watch the ATM tutorial series here:
• Python / TKinter - ATM...
Sponsor me on GitHub!
github.com/sponsors/miguelznunez
Follow my blog:
/ miguelznunez
Email : mignunez@csumb.edu
Medium : / miguelznunez
Codepen : codepen.io/miguelznunez
GitHub : github.com/miguelznunez
This is a really great tutorial, thank you so much you saved me from falling into a heavy frustration
No problem 👍
Fantastic tutorial, no need to create classes! Thank you so much!
Great work man, this really helped me. 👍👍👍 Keep making such tutorials. ❤️❤️
Thanks, please like the video if it helped!
@@codefoxx already did sirrr.
Brilliant tutorial! very well explained
Glad you liked it!
Brilliant tutorial! very well explained. I just SUBSCRIBED
Thank you so much this is exactly what I needed. You made my work easy.
God bless you☺
This is exactly what i was loking for! Thanks a lot.
No problem 👍
Thanks for the video. Really helpful
old video but just came across it and it helped me alot! This was just the thing i was looking for
thank you so much for this tutorial, you really helped me a lot
Finally I got this type of video. Thanks bro
No problem, thanks for watching 📺
Great content as always 👏
Glad you enjoyed it
Thank you very much. It was really useful
Thank you so much for this tutorial sir !!
I am korean and this is sooooooooooooo great for me. This videos is more helpful than korean blog sites thank you
Thanks this is great basic tutorial for multiple pages gui
Really really Thanks!
Thanks, man! Greetings from Perú 🇵🇪
No problem!
Thank you!
I needed this thanks
No problem
Excellent job dude
Thanks
Cool. Thanks man
You saved me man, ver very Thank you.. tomorrow is my hackathon project submission nd jst linking part was left
Thank you ❤️, the other one is too hard for me.
Awesome video, python, java, flutter, which language I should choose to create a GUI app for rasbian (virtual environment), I want to create an app on my windows pc, and when it's done I just want to test how it is working in rasbian and than in real raspberry pi 4.
I don't want to install any additional module from the terminal, I want something that can directly run on rasbian
Hey, thanks for the idea. I am trying to use it where I have 3 frames at a time on a screen and I just want to update only one frame but it isn't working for me?
Can you please help
Nice video thank for this
No problem 👍
Brilliant video. If the user wants an image as the background, they will have to use a canvas. It is possible to do the same thing using canvases?
THANKS!!!
Thanks a lot.
Why is this such a good video
Not sure, I feel like I could have done a better job! Thanks
@@codefoxx idk why this is sl good but i think it´s bcs you are going slow and expalining everyrhing
you got a new sub
Thanks
is there anyway to do this with canvas? my program I'm trying to create heavily relies on canvas'.
How did you make the color, fill the window?
Hi bro, loved the video. Just a question tho, how can i make it like full size? In the intro you've got like these big frames but in the video they are small. Thanks
Instead of (fill="x") use (fill="both" expand="true") when you pack the Label. You can add as many things as you want per frame, I just used the Label and button on each frame to demonstrate how it works
Thanks, got 10 on my project ;)
@@gabrielolvera8321 there u go!
Massa o vídeo.
what should we code if we want frame 1 as default and frame 2 , 3 should be under a menu button . when we click the menu button , i should get 2 options (frame 2 and frame 3) and when clicked the frame 2 or 3 , still the menu should be available and when we are in frame 2 or frame 3 , the menu button should show frame 1 so that i can go back to frame 1 .
please reply the code or make a video on it in short term . pls
You would have to create a menu bar and add the those two options to it. When a user clicks on the frame 2 option, for example, you would use the show_frame function to take them to that page. Doesn't seem too difficult
@@codefoxx thanks 🤗 . Love your videos . Really helpful . Keep rocking .
can I ask u a question? can I double the layer without actually changing the back layer, for example, I have 2 layers, the first layer is the main layer, the second layer is like 'pop up' image with the blurry main layer behind it(without actually changing the data in the main layer)?
I think I know what you mean. Not sure if you can do this with tkinter. That sounds more like something that is done with CSS in web development.
@@codefoxx yea true 🤣, how about I change the layer, but the data in main layer I set to global, is that doable?
@@muhammadbangkit7528 Not sure, try it! I have not worked with tkinter in over a year sorry I can't be of much help!
@@codefoxx okok thanku very much sir
I'll put ur channel on my paper as references, thanku very much 🙏
this code is not working with pack method please help.
i am having issues with the button name not being defined, idk what I did wrong and i followed your steps.
That error is usually a typo. Please check the names of your buttons and make sure they match up
Can u please say how to import photos in dis method that is using diff photos in diff window please make it sir
Email me, my email is in the description, I can send you an example of that
@@codefoxx ok sir thanku
@@sairsc8043 I do something similar to what you want in this video, if you still need help, email me
ruclips.net/video/2V2QxFBMEyo/видео.html
Great video. Exactly what I was looking for. Btw, do you know how to create android apps using python? I just found Java but I don't want it.
With Python you can use Kivy to make apps, although I don't know how to use it. I personally use Java with Android studio to make apps. Yes, Java can be more confusing than Python being that it's entirely based on object oriented programming. Hope this helps
@@codefoxx I know the basis of POO from c++ (I guess is kinda same) but Java seems more complex for me. Anyway thanks for the information, I'll keep it in mind.
@@ChicaRara01 nice, I recommend you use OOP because if you want to make something other than a beginner program, respectively, (something more complex with a lot of functionality) you will need OOP because it will give your code a better structure and it will help keep it organized when you get into the several hundred/ thousands lines of codes. It will also make it easier to add or delete things from your project!
@@codefoxx sure, thank u for the explanation.
Bro is there any way that I can make dark to light theme switcher in tkinter?
Absolutely
I can't add exit button :/ can anyone help me ?
Hi. I had multiple problems with the code as appearing in your video. I modified it a bit to work. I'm using python 3.10.6
import tkinter as tk
window = tk.Tk()
# Ori = window.state('zoomed')
window.geometry("800x700") # auto shows full size
def show_frame(frame_number):
frame_number.tkraise()
# window.rowconfigure(0,weight=1)
# window.columnconfigure(0,weight=1)
frame3 = tk.Frame(window, width=700, height=200, bg = 'black')
frame3.place(x=0,y=0)
frame2 = tk.Frame(window, width=700, height=200, bg = 'gray')
frame2.place(x=0,y=0)
frame1 = tk.Frame(window, width=700, height=200, bg = 'orange')
frame1.place(x=0,y=0)
# for frame in (frame1, frame2, frame3):
# frame.grid(row=0,column=10,sticky="nsew")
# ==========================
frame1_title = tk.Label(frame1, text="This is frame1", bg='skyblue')
frame1_title.place(x=30,y=50) # relative to 0,0 in the frame !!!!!!
frame1_btn = tk.Button(frame1, text='see Frame2', command=lambda:show_frame(frame2))
frame1_btn.place(x=30,y=100)
frame2_title = tk.Label(frame2, text="This is frame2", bg='yellow')
frame2_title.place(x=30,y=50) # relative to 0,0 in the frame !!!!!!
frame2_btn = tk.Button(frame2, text='see Frame3', command=lambda:show_frame(frame3))
frame2_btn.place(x=30,y=100)
frame3_title = tk.Label(frame3, text="This is frame3", bg='pink')
frame3_title.place(x=30,y=50)
frame3_btn = tk.Button(frame3, text='see Frame1', command=lambda:show_frame(frame1))
frame3_btn.place(x=30,y=100)
window.mainloop()
what's IDE setting? espacialy what's font?
i am having a problem that my frame3 is coming at 1st instead of frame1
How to go back from page 2 to page1?
Use the show_frame(frame1) function
when I run the program both show up and frame 2 wont disappear I'm using only 2 frames
You must be doing something wrong, look at the tutorial again or send me your code and I can look at it
@@codefoxx oh okay sure, I tryed many different things so far. But nothing seems to work
@@codefoxx
from tkinter import *
wn = Tk()
wn.geometry("400x300")
Play = Frame(wn)
TitleScreen = Frame(wn)
def swap(frame):
frame.tkraise()
for frame in (Play, TitleScreen):
frame.grid(row=0, column=0)
#Title Screen#
Button(TitleScreen, text="Play", command=lambda: swap(Play)).grid(row=0, column=0)
Button(Play, text="TitleScreen", command=lambda: swap(TitleScreen)).grid(row=0, column=0)
show_frame(Play)
wn.mainloop()
@@codefoxx I tryed removing show_frame(0 before and it still doesn't work
@@codefoxx Never mind, I forgot labels
Thanks for teach...
Can change this game tic tac toe for Desktop Applicatio
No problem 👍
the sound volume from intro is too loud. great tutorial
I have made efforts to improve my sound quality since that video was recorded. Thanks for letting me know and for watching 📺
can ya help me i don't know why my frame starts from frame 3
Sure, did u make a function call to the show_frame function at the bottom of the program?
If you haven't, make a function call to show_frame(frame1), at the bottom of the program. That should make frame1, the one that shows up when you run the project
@@codefoxx i see.. thank you very much
@@bluezzyy5360 no problem
Uh.. looks like I have more problem.
If I add sticky = 'nsew', there's nothing appear on the program. But if I get rid of it, the title, button and etc were appeared. So the difference between my code and your code on your tutorial video, I add entry in the frames. So, is that the one causing the problem?
I have a problem. It says, can't invoke pack command the application has been destroyed and I don't know why. ¿Cuold you help me to figure out what is wrong or what am I missing?
from tkinter import *
import time
#----------------------SHOW FRAMES-------------------------
def show_frame(frame):
frame.tkraise()
window=Tk()
window.title("PPA")
window.config(bg="white")
window.state("zoomed")
frame1=Frame(window)
frame2=Frame(window)
frame3=Frame(window)
for frame in (frame1,frame2,frame3):
frame.pack()
frame1.config(bg="blue")
boton=Button(frame,width=10,height=2, relief="raised", text="SUBJECTS",fg="white",command=lambda:show_frame(frame2))
boton1.pack()
frame2.config(bg="black")
boton2=Button(frame,width=10,height=2, relief="raised", text="CALCULATOR",fg="white",command=lambda:show_frame(frame3))
boton2.pack()
frame3.config(bg="red")
boton3=Button(frame,width=10,height=2, relief="raised", text="MAIN MENU",fg="white",command=lambda:show_frame(frame1))
boton3.pack()
window.mainloop()
Working out right now but I'll look at your code in 30min
@@codefoxx yay, thanks.
@@ChicaRara01 Ok, there was a lot of things missing from your code, for example, you didn't import the tkinter module nor did you call on the show_frame function. I fixed your code although I am not 100% sure what your aiming for in this project. I added a button to each of the frames. Below is the code
import tkinter as tk
def show_frame(frame):
frame.tkraise()
window=tk.Tk()
window.title("PPA")
window.config(bg="white")
window.state("zoomed")
window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)
frame1=tk.Frame(window)
frame2=tk.Frame(window)
frame3=tk.Frame(window)
for frame in (frame1,frame2,frame3):
frame.grid(row=0,column=0,sticky='nsew')
frame1.config(bg="blue")
boton1=tk.Button(frame1,width=10,height=2, relief="raised", text="SUBJECTS",fg="white",command=lambda:show_frame(frame2))
boton1.pack()
frame2.config(bg="black")
boton2=tk.Button(frame2,width=10,height=2, relief="raised", text="CALCULATOR",fg="white",command=lambda:show_frame(frame3))
boton2.pack()
frame3.config(bg="red")
boton3=tk.Button(frame3,width=10,height=2, relief="raised", text="MAIN MENU",fg="white",command=lambda:show_frame(frame1))
boton3.pack()
show_frame(frame1)
window.mainloop()
@@codefoxx not pretty sure why didn't work if before trying to switch between frames(I made a simple interface with just one frame and it worked perfectly) but thank u, I really appreciate. Anyway you got a new subscriber since a saw your video for the first time. Great job.
how to solve it for a pin condition .
Not sure what you mean 🤔
@@codefoxx if atm pin is there so how to do if condition
@@switchblade3868 here is some pseudo code.......if(password == yourPassword){ showFrame(go to this frame)}
else{ sorry wrong password}
@@codefoxx luv u babes made it
And please teach how to create tic tac toe game to desktop aplikatio
I already have a tutorial on a tic tac toe game. Here is the link ruclips.net/video/FrkofcY9whY/видео.html
Can you please share the code with me
Yea it's on GitHub. Link in the description
@@codefoxx oh Thanks bro ♥️♥️
@@mr.bubble1657 I got chu
Broh can you share the code plz
No problem, I left a link in the description to the github repo
@@codefoxx Bro Can we do the same using "place" instead of "pack"
@@hartech6162 I have not coded with Python in months but when I did, I rarely used place. I either used grid or pack. I read that it was bad practice to use place once but not exactly sure why. Besides, nearly everything that you would want to do can be accomplished with grid and/or pack. So to answer your question, you would have to try to find out
@@codefoxx Oh ThankYou So much broh for ur help it helped me a lot in my project
Bro can i put scroll bar for labels