In this post, you will learn how to open a window/frame by clicking a button in Tkinter. If you want to pass parameters between two frames click Tkinter Passing Variables Between Windows post.
Python Code: How to open a new frame from a current window in python tkinter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from tkinter import * class Frames(object): def newWindow(self): # new window definition newwin = Toplevel(root) newwin.title('New Window') newwin.geometry("200x100") newwin.resizable(0, 0) display = Label(newwin, text="Humm, see a new window !") display.pack() def mainFrame(self,root): root.title('Open New Window!!!') root.geometry("200x200") root.resizable(0, 0) button1 =Button(root, text ="open new window", command =self.newWindow) button1.place(x = 50, y = 25, width=100, height=25) root = Tk() app = Frames() app.mainFrame(root) root.mainloop() |
Output: