The ' tkinter tutorial toplevel '
# TopLevel is similar to frame, but it contains form attributes (such as title)
' 1. Create simple TopLevel '
#-*-coding: Utf-8-*-from
tkinter import *
root = Tk ()
tl = toplevel ()
# to distinguish between Root and TL, we added a label label to the TL
(TL , text= ' Hello label '). Pack ()
root.mainloop ()
# The Run result generates two forms, one is started by root, and the other is created by TopLevel, which contains a label;
# Close TL does not exit the program, TK still works; If you turn off TK, the entire TK end TL ends and it cannot exist alone.
' 2. Set toplevel properties ' '
# title set heading
# Geometry set width and height
#-*-coding:utf-8-*-from
tkinter import *
root = Tk ()
tl = toplevel ()
# Set the title
tl.title (' Hello TopLevel ') of the TL
to set the TL in width and height
Tl.geometry (' 400x300 ')
# to distinguish between Root and TL, we added a label
label (TL, text= ' Hello Label ') to the TL. Pack ()
Root.mainloop ()
' 3. Use TopLevel to make your own cue box '
#-*-coding:utf-8-*-from
tkinter import *
root = Tk ()
mbyes, Mbyesno, Mbyes Nocancel, Mbyesnoabort = 0, 1, 2, 4
# define a message dialog box that, depending on the parameters passed in, pops up a different message
def MessageBox (): # No use parameters are used
Mbtype = Mbyesno
textshow = ' yes '
if Mbtype = = Mbyes:
textshow = ' yes ' elif mbtype = = Mbyesno
:
textshow = ' Yesno '
elif mbtype = = Mbyesnocancel:
textshow = ' yesnocancel ' elif
mbtype = = Mbyesnoabort:
Textshow = ' Yesnoabort '
tl = toplevel (height=200, width=400)
Label (TL, text=textshow). Pack ()
# This message box is started by a Button because it uses an empty callback function, so MessageBox changed to a parameterless form, using a fixed
# value Mbyesno
Button (Root, text= ' Click Me ', command= MessageBox). Pack ()
Root.mainloop ()