[英]How to change the font of text in tkinter Python
I want to change the text font in tkinter.我想更改 tkinter 中的文本字体。 How am I supposed to do that?
我该怎么做? I am new to tkinter and I don't understand.
我是 tkinter 的新手,我不明白。 Also, I have inserted a text, is its syntax correct?
另外,我插入了一个文本,它的语法是否正确?
self.text = tk.Text(parent)
self.text.insert(tk.END, "Welcome to Emotion Detector!")
self.text.pack()
I have only imported tkinter as tk.我只将 tkinter 作为 tk 导入。 nothing else.
没有其他的。 Am I supposed to import anything else?
我应该导入其他东西吗?
For setting the font, font size and type you can use the the tuple:要设置字体、字体大小和类型,您可以使用元组:
self.text.configure(font = ("Arial", 20, "bold"))
Syntax for text insertion is ok, but there are neater ways of doing this, depending on what you are trying to achieve, fe using labels (which have method.config):文本插入的语法是可以的,但是有更简洁的方法可以做到这一点,具体取决于您要实现的目标,fe 使用标签(具有 method.config):
self.label = Label(parent, text = "Some text")
self.label.config(font = ("Courier New", 14))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.