- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 do I make a pop-up in Tkinter when a button is clicked?
Popup window in Tkinter can be created by defining the Toplevel(win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application. We can create a top-level window or a child window by initializing the object of Toplevel(parent). It inherits all the property of its parent window, such as geometry, title, and width or height.
In this example, we will create a button that will open a Popup window above all the other windows.
#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter frame win.geometry("750x270") def open_popup(): top= Toplevel(win) top.geometry("750x250") top.title("Child Window") Label(top, text= "Hello World!", font=('Mistral 18 bold')).place(x=150,y= 80) Label(win, text=" Click the Below Button to Open the Popup Window", font=('Helvetica 14 bold')).pack(pady=20) #Create a button in the main Window to open the popup ttk.Button(win, text= "Open", command= open_popup).pack() win.mainloop()
Running the above code will display a window that will have a button to open the Popup Window.
Now, click the Open button to Open the Popup window. Once we click the "Open" button, a popup window will appear on the screen.
- Related Articles
- How can I identify when a Button is released in Tkinter?
- How can I play a sound when a Tkinter button is pushed?
- How to prevent a dialog from closing when a button is clicked?
- How to put url into a variable when button is clicked - jQuery?
- Execute a script when a reset button in a form is clicked in HTML?
- How to prevent a dialog from closing when a button is clicked using Kotlin?
- How do I change button size in Python Tkinter?
- How do I automatically download files from a pop up dialog using selenium-python?
- How to change color of Button in Android when Clicked?
- Change Color of Button in iOS when Clicked
- Running multiple commands when a button is pressed in Tkinter
- How to make a Button using the Tkinter Canvas widget?
- How do you create a Button on a Tkinter Canvas?