0
是否可以在python中的tkinter框中調整文本大小?我知道我可以添加文字,並且當這樣做時,還可以定義字體大小。是否可以調整文本的大小,如果說,觸發程序這樣做?在tkinter框中調整文本大小
是否可以在python中的tkinter框中調整文本大小?我知道我可以添加文字,並且當這樣做時,還可以定義字體大小。是否可以調整文本的大小,如果說,觸發程序這樣做?在tkinter框中調整文本大小
如果您使用的是Text
框,您可以使用標籤來格式化其內容。例如:
#!/usr/bin/env python
import Tkinter
import tkFont
class App:
def __init__(self):
# Set up the text box
self.root = Tkinter.Tk()
self.text = Tkinter.Text(self.root, width=20, height=5)
self.text.insert(Tkinter.INSERT, "Hello...")
self.text.pack()
# set up a mouse event
self.text.bind("<Button-1>", self.click)
# Set Tkniter's main loop
self.root.mainloop()
def click(self, event):
self.text.tag_add("here", "1.0", "1.4")
self.text.tag_config("here", background="yellow", font=tkFont.Font(size=36))
if __name__ == "__main__":
App()
當您用鼠標單擊該框時,將更改輸入文本部分的背景和大小。