Tkinter

How to Open a New Window With a Button in Python Tkinter

In this tutorial, we are going to see how to open a new window with a button in Python Tkinter. Usually we use tk.Tk() to create a new Tkinter window, but this is not valid if we have already created a root window.
 

How to Open a New Window With a Button in Python Tkinter

In the following example, we will use the Toplevel widget, because the Toplevel widget is intended to display additional ‘pop-up’ windows.
 

 

from tkinter import *   

def create():
    win = Toplevel(root)

root = Tk()
root.geometry('200x100')  

btn = Button(root, text="Create a new window", command = create)
btn.pack(pady = 10) 

root.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

One thought on “How to Open a New Window With a Button in Python Tkinter

  • Marco Antonio

    Excelente trabajo felicitaciones

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *