Tkinter (12) 讯息部件 Message

讯息部件的创建及其选项

类似标签部件, 主要用来显示多行同字体的讯息.

import tkinter as tk
parent = tk.Tk()
message = tk.Message(parent, option, ...)
选项 说明
aspect 寛度相对于高度的百分比, 内定为150
bg or background 背景颜色
bd or borderwidth 框的寛度, 内定为2点素, 在 relief 非 tk.FLAT 时才可见
cursor 当鼠标移到部件时,所显示的鼠标图示
font 文本字体
fg or foreground 前景色
highlightbackground 非聚焦时的聚焦颜色
highlightcolor 聚焦时的聚焦颜色
highlightthickness 聚焦厚度
justify 多行文本的对齐方式,LEFT/RIGHT/CENTER
padx 水平间距点素
pady 垂直间距点素
relief 花边样式,内定为 FLAT
takefocus TAB 键在部件是否会循环焦点,True 则会,内定为不会
text 文本字串
textvariable 文本字串变量
width 文本寛度点素,内定寛度与显示文本与 aspect 值有关

范例视窗及代码

Tkinter (12) 讯息部件 Message

import tkinter as tk

root = tk.Tk()
root.wm_title("Message Demo")

t = ("Python is an easy to learn, powerful programming language. It has "
     "efficient high-level data structures and a simple but effective "
     "approach to object-oriented programming. Python’s elegant syntax and "
     "dynamic typing, together with its interpreted nature, make it an ideal "
     "language for scripting and rapid application development in many areas "
     "on most platforms.")

font = ('Courier New', 20, 'bold')

message = tk.Message(text=t, aspect=500, font=font)
message.grid()

root.mainloop()
本作品采用《CC 协议》,转载必须注明作者和本文链接
Jason Yang
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!