Message in tkinter tutorial

Source: Internet
Author: User
Tags tkinter tutorial

This article Reprinted from: http://blog.csdn.net/jcodeer/article/details/1811326

''' Tkinter message '''
# Message is used to display text. Its usage is basically the same as that of label.
'''1. Create a simple message '''
From tkinter import *
Root = TK ()
Message (root, text = 'Hello message'). Pack ()
Root. mainloop ()
# Run the program. After you see hello, the message is displayed in the next line. This is also a feature of message. No label.

'''2. If you do not want it to wrap, specify a sufficiently large width '''
From tkinter import *
Root = TK ()
Message (root, text = 'Hello message', width = 60). Pack ()
Root. mainloop ()
# Run the program. After you see hello, the message is displayed in the next line. This is also a feature of message. No label.

'''3. Use the aspect attribute to specify the width-to-height ratio '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
For I in range (10 ):
Message (root, text = 'A '* I, aspect = 400). Pack ()
Root. mainloop ()
# The default value is wider/Height = 1.5. You can use the aspect attribute and set it to 4, which is four times the width is high. 10 'A' values can be displayed'

''4message: bind the variable '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
V = stringvar ()
V. Set ('000 ')
For I in range (10 ):
Message (root, text = 'A', textvariable = V). Pack ()
# Print the current value of V. If the value of one of the messages changes, the value of V changes.
Print v. Get ()
Root. mainloop ()
# Bind the variable v. Although text is used to specify the message value during message creation, the bound variable has a high priority and can change the text
# The specified value.

'''5. Test the justify attribute '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
For I in [left, right, center]:
Message (root, text = 'abc def ghi', justify = I). Pack ()
Root. mainloop ()
# The displayed text is automatically disconnected. The upper and lower lines are left-aligned, right-aligned, and center-aligned respectively.

Message in tkinter tutorial

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.