'''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 ()
# Author: jcodeer
# Blog: jcodeer.cublog.cn
# Email: jcodeer@126.com