简体   繁体   中英

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM