Gui (tkinter (Label, button)

Source: Internet
Author: User
Import tkinter
From tkinter import *

# Tkinter. _ test ()

# Instantiate a window object
Base = tkinter. TK ()
# Modify the title of a window
Base. wm_title ("window ")

# Use of components

"""
# Label component
# Component usage is similar. when instantiating these components, the first parameter is a parent window or parent component, followed by some attributes of the component.
# For example, the text attribute and background attribute of label
W1 = label (base, text = "Learn tkingter along with xingge", background = "green ")
W2 = label (base, text = "I love python, because it is concise", background = "red ")
W3 = label (base, text = "Create a dream, start from now", background = "yellow ")

# Pack method layout. You can also use place and grid for layout management.
W1.pack ()
W2.pack ()
W3.pack ()
"""

# Button component


'''
The binding methods are usually as follows:
First, use the command attribute declaration when the button component is declared. The command attribute accepts a function name. Note that the function name should not be enclosed by double quotation marks.
Second, use the bind method, which is a method of the MISC class,
'''

# First event binding method
# Do not add any punctuation marks after the command attribute
'''
Def xinlabel ():
Global Base
S = label (base, text = "I love Python", background = "green ")
S. Pack ()

B1 = button (base, text = "button", command = xinlabel)
B1.pack ()
'''

# Event binding method 2
Def xinlabel (event ):
Global Base
S = label (base, text = "I love Python", background = "green ")
S. Pack ()

B1 = button (base, text = "button ")
# The first parameter of BIND is the event type, which is described as follows: <modifier-type-Detail>, here
# Modifier is the modifier. Its values are as follows: control, mod2, M2, shift, mod3, M3, lock, mod4, M4, button1, B1, mod5, M5 button2, b2, Meta, M, button3, B3, ALT, button4, B4, double, button5, B5 triple, mod1, M1. The third type indicates the type, and its values are as follows: Activate, enter, MAP, buttonpress, button, expose, motion,
# Buttonrelease, focusin, mousewheel, circulate, focusout, property, colormap, gravity reparent, configure, keypress, key, unmap, deactivate, keyrelease visibility, destroy, and leave. The third parameter table shows the details, which is an auxiliary description of the second parameter.
# The first parameter may be too complex for the person who just used it. The common left-click button is as follows: <button-1>,
# That is, what I used in the above Code
# The second parameter can be a function name. Remember not to add any punctuation marks. Otherwise, an error will be reported during running.
# When using the BIND function, the second parameter is a function name, which must accept a parameter, that is, the event
B1.bind ("<button-1>", xinlabel)
B1.pack ()


# Message loop
Base. mainloop ()

Gui (tkinter (Label, button)

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.