Toplevel for tkinter tutorials

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.