Tkinter Message 使用字符串变量处理text参数
示例1
以字符串变量方式处理Message( )内的text。
from tkinter import *
root = Tk()
root.title("apidemos.com")
var = StringVar()
msg = Message(root,textvariable=var,relief=RAISED)
var.set(
"""apidemos.com provides tutorials on the basics of programming, introducing the basics of various programming languages such as HTML, CSS, Javascript, Python, Java, Ruby, C, PHP , MySQL and more. The site also provides a large number of online examples, through the examples, you can better learn programming..."""
)
msg.pack(padx=10,pady=10)
root.mainloop()
输出:
示例2
扩充上述实例,将背景设为黄色。
from tkinter import *
root = Tk()
root.title("apidemos.com")
var = StringVar()
msg = Message(root,textvariable=var,relief=RAISED,font="times 30 italic")
var.set(
"""apidemos.com provides tutorials on the basics of programming, introducing the basics of various programming languages such as HTML, CSS, Javascript, Python, Java, Ruby, C, PHP , MySQL and more. The site also provides a large number of online examples, through the examples, you can better learn programming..."""
)
msg.config(bg="yellow")
msg.pack(padx=10,pady=10)
root.mainloop()
输出: