Rubinjo13
Rubinjo13

Reputation: 65

How to open a toplevel window with a button python 3/Tkinter

root = Tk()
root.geometry("1600x800+0+0")
root.title("Tronios Exportzendingen")

invoerscherm = Toplevel()
invoerscherm.geometry("800x400+0+0")
invoerscherm.title("Nieuwe Zending Invoeren")

root.mainloop()

Both windows are opening when executing the code.

I want the toplevel to open with a button in the root window.

How can i do that?

Upvotes: 0

Views: 2582

Answers (1)

Taku
Taku

Reputation: 33714

You never made a button, you can create a button and set the command.

root = Tk()
root.geometry("1600x800+0+0")
root.title("Tronios Exportzendingen")
def set_button():
    invoerscherm = Toplevel()
    invoerscherm.geometry("800x400+0+0")
    invoerscherm.title("Nieuwe Zending Invoeren")
but = Button(text="Press Me", command=set_button)
but.pack()
root.mainloop()

Upvotes: 1

Related Questions