- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to open a new window by the user pressing a button in a tkinter GUI?
Tkinter creates a default window (i.e., master or root window) for every application. In tkinter, we can create a Popup window or a child window by defining a Toplevel(master) constructor. This will allow the tkinter application to create another window which can be resized dynamically by defining its size property.
In this example, we have created a button widget that will open the new window with a text label.
#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Define a new function to open the window def open_win(): new= Toplevel(win) new.geometry("750x250") new.title("New Window") #Create a Label in New window Label(new, text="Hey, Howdy?", font=('Helvetica 17 bold')).pack(pady=30) #Create a label Label(win, text= "Click the below button to Open a New Window", font= ('Helvetica 17 bold')).pack(pady=30) #Create a button to open a New Window ttk.Button(win, text="Open", command=open_win).pack() win.mainloop()
Running the above code will display a window that contains a button widget. When we click the button, it will open a new Window.
Now, click the "Open" button to open a new Window.
- How to close a Tkinter window by pressing a Button?
- How do I open a website in a Tkinter window?
- How to specify where a Tkinter window should open?
- Call the same function when clicking a Button and pressing Enter in Tkinter
- How to open a new window on a browser using Selenium WebDriver for python?
- How do you create a Tkinter GUI stop button to break an infinite loop?
- How to keep the window focus on the new Toplevel() window in Tkinter?
- How to add a margin to a tkinter window?
- Execute a script when a user is pressing a key in HTML?
- How to bind a key to a button in Tkinter?
- Tkinter-How to get the current date to display in a tkinter window?
- How to create a Tkinter toggle button?
- How to set a Tkinter window to a constant size?