This article Reprinted from: http://blog.csdn.net/jcodeer/article/details/1811341
'''Tkinter toplevel '''
# Toplevel is similar to frame, but it contains form attributes (such as title)
'''1. Create a simple toplevel '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
TL = toplevel ()
# To distinguish between root and TL, we add a label to TL.
Label (TL, text = 'Hello label'). Pack ()
Root. mainloop ()
# Two forms are generated in the running result. One is started by root, and the other is created by toplevel, which contains a label. Disable tl
# The program is not exited, and TK still works. If TK is disabled, the entire TK end TL also ends, and it cannot exist independently.
'''2. Set toplevel attributes '''
# Title setting title
# Geometry setting width and height
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
TL = toplevel ()
# Set TL title
TL. Title ('Hello toplevel ')
# Set Tl in width and height
TL. Geometry ('400x300 ')
# To distinguish between root and TL, we add a label to TL.
Label (TL, text = 'Hello label'). Pack ()
Root. mainloop ()
''' 3. Use toplevel to create a prompt box '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
Mbyes, mbyesno, mbyesnocancel, mbyesnoabort = 0, 1, 2, 4
# Define a message dialog box. Different prompts are displayed based on different input parameters.
Def MessageBox (): # No parameters 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 ()
# The message box is started by the button. because it uses an empty callback function, the MessageBox is changed to the parameter-free format and fixed
# Value: mbyesno
Button (root, text = 'click me', command = MessageBox). Pack ()
Root. mainloop ()
Toplevel for tkinter tutorials