The TopLevel chapter of Tkinter Tutorial

Source: Internet
Author: User
Tags pack tkinter tutorial
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 ()

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.