

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
Example
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()
Output
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.
- Related Questions & Answers
- How to close a Tkinter window by pressing a Button?
- How to open link in a new window - JavaScript?
- How do I open a website in a Tkinter window?
- How to specify where a Tkinter window should open?
- How to open a URL in a new tab (and not a new window) using JavaScript?
- 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?
Advertisements