Multiple Windows/Frames in Tkinter GUI with Python - Tkinter tutorial Python 3.4 p. 4
Why Stack Overflow recommends it
Stack Overflow users link it when someone needs to switch between multiple pages or frames in a Tkinter app, since it walks through the class-based container and tkraise pattern step by step.
Recommended by 8 people across 8 different months, 2015 to 2022.
What it is
Part 4 of sentdex's Tkinter tutorial series for Python 3.4. It shows how to switch between multiple pages in one Tkinter window by building each page as a Frame class and raising the one you want. The page-switching code is adapted from a well-known Stack Overflow answer.
What people said
Strong rec student23 · 2018-01 · Stack Overflow · on “_tkinter.TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number”
I am no Tkinter expert, and I know this isn't a multiple windows question, but you claim that you click a button and get on a new page so your issue might be related to what I have to say. I seem to remember something about having a single application window and then populating that window with a new frame on user actions and events. Each frame would be a class, and then you would have some kind of loop that allows you to "refresh" the windows content with a new frame. When I found this guy and his videos on youtube [this video] it really helped me to learn Tkinter and overcome the newbie GUI programming issues (like multiple windows). Follow his playlist and you will be sorted in no time. It als
Recommends Treeno1 · 2016-04 · Stack Overflow · on “Switching Frames in Tkinter”
I've come across this great tutorial - [this video] its part 3, its essentially just about being able to swap out frames with the press of a button. I've pretty much followed all the steps and everything works up until about 7.06 here is the code - import Tkinter as tk class MainApp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack(side = "top", fill = "both", expand = True) container.grid_rowconfigure(0, weight = 1) container.grid_columnconfigure(0,weight = 1) self.frames = {} for F in (StartPage,PageOne): frame = F(container,self) self.frames[F] = frame frame.grid(row = 0, column = 0, sticky = "w") self.show_frame(StartP
Recommends double_j · 2016-08 · Stack Overflow · on “Tkinter - Understanding how to switch frames”
@BryanOakley In case you were still looking, I've seen this [this video] tutorial that uses your code from the original question [LINK] , although he does say where it came from. There's also this [LINK] .
Recommends Sébastien S. · 2017-07 · Stack Overflow · on “Python frames tkinter”
I suggest you to follow this tkinter GUI tutorial [this video] , he makes a pretty big app and even if it's not what you exactly looking for, it will help you. In the part 4, he make a multiple frame architecture in the tkinter GUI. For switching "pages", i know 2 choices (there's more i think but i don't know them, i'm still a beginner). You can create all the frames inside a window/Frame and raise to the front the one you want (that's in the tutorial part 4) or you can destroy the widgets "Page 1" inside the body frame and create the widgets "Page 2" inside it (obviously in methods/functions to let you switch between the pages). For your first problem, i'm not sure if i understand your problem,
Recommends t.hall · 2017-09 · Stack Overflow · on “How can I open a new window when the user clicks the button?”
Take a look at [this video] . Working through this tutorial would probably help you but this specific video shows how to work with multiple pages. Something like this: from tkinter import * class Sample(Tk): def __init__(self,*args, **kwargs): Tk.__init__(self, *args, **kwargs) container = Frame(self) container.pack(side="top", fill="both", expand = True) self.frames = {} for F in (MainPage, OtherPage): frame=F(container, self) self.frames[F]=frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(MainPage) def show_frame(self, page): frame = self.frames[page] frame.tkraise() class MainPage(Frame): def __init__(self, parent, controller): Frame.__init__(self, parent) Label(self, text="Sta
Recommends LukeDev · 2019-06 · Stack Overflow · on “Get result of a button that runs askopenfilename”
You can't retrieve the data in the buttons function call. If you had a global variable, def openfile(): global filename = tkinter.filedialog.askopenfilename(filetypes = (("Excel", "*.xlsx"), ("All files", "*.*"))) print(filename) , you could access it from outside the function called by a button. How I've gotten around this in the past is by using classes. This tutorial [this video] online splits the tkinter program into classes. If you followed this structure you could create a class variable filename . This would allow you to manipulate the file within that instance of the class.
Recommends gMoney · 2020-04 · Stack Overflow · on “How to assign button in TkInter to my script?”
I suggest looking into creating multiple pages and creating buttons that function to go between pages. this way you understand how tkinder functions and is structured when you build your own application. Then work on this practice, you can check out [this video] if you find video tutorials best but this isnt exactly the best tutorial
Recommends Harsh Kasodariya · 2021-09 · Stack Overflow · on “Python entry widget inside a function”
I think the way you implemented the second window b is causing the problem. There should always be only one root window in the tkinter application. All other windows should be the toplevel widgets for the root window. This code should work. from tkinter import * # Root window a = Tk() # All other windows should be the toplevel widgets for this root window def reg(): global b b = Toplevel(a) global ab ab = IntVar() E = Entry(b,textvariable=ab).pack() b2 = Button(b, text='submit',command=lambda:sub()).pack() def sub(): l = ab.get() Lab = Label(b, text=l).pack() b1 = Button(a, text='reg',command=lambda:reg()).pack() a.mainloop() Watch this video [this video] . It has a better implementation and expl
Cites Raz89 · 2015-04 · Stack Overflow · on “Python Tkinter, avoid code repetition by bring a variable when going to a new window (a new class)”
first question ever asked! I am new to both Python and Tkinter and followed this guide to create multiple windows with Tkinter: [this video] When the user makes a choice in the first window, lets say we have a button for each month, and three of the buttons (june, july, august) represents Summer. Like this: months = ["january", "february" and so on] for i in months[0:2]: button = tk.Button(self, text=i, command=lambda:controller.show_frame(PageWinter)).pack() for i in months[2:5]: button = tk.Button(self, text=i, command=lambda: controller.show_frame(PageSpring)).pack() Now the thing is that I have created a class for each season. It works fine but, except the season, all the code is just the sam
Cites Mathew Wright · 2016-11 · Stack Overflow · on “tkinter switching between frames using oop”
I am new to oop and I would like some assistance. I use a lambda to initalise the process of changing the frame, however I am unable to use the lambda inside of a function (method) in a class. This is the lambda that normally works to change to the canteenpage: lambda: controller.show_frame(CanteenPage) I have been using this tutorial: [this video] Original version of code : Switch between two frames in tkinter [LINK] code: import tkinter as tk from tkinter import ttk class CashlessService(tk.Tk): def __init__(self, *args, **kwards): tk.Tk.__init__(self, *args, **kwards) tk.Tk.wm_title(self, "CashlessService") container = tk.Frame(self) container.pack(side="top", fill="both", expand = True) conta