訊息部件的建立及其選項
類似標籤部件, 主要用來顯示多行同字型的訊息.
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 值有關 |
範例視窗及程式碼
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 協議》,轉載必須註明作者和本文連結