![](/img/trans.png)
[英]How to only change font size of text widget in tkinter(not family)
[英]Tkinter does not change font family
我想更改字体系列,但它不起作用。
from tkinter import *
import tkinter.font as font
class Window:
def __init__(self):
root = Tk()
def_font=font.Font(family='Times')
root.title("Serial Conection Program")
self.mainFrame= Frame(root)
self.portLabel=Label(self.mainFrame, text="Port: ",font= def_font)
....
....
我正在尝试类似 normal font= 'Times'
,但这也不起作用......
也许解释器有问题(我使用 python 3.6.1-anaconda3)?
它究竟是如何不起作用的? 正如您在屏幕截图中看到的那样,以下对我有用(使用 Python 3.6.2):
from tkinter import *
import tkinter.font as font
class Window:
def __init__(self):
root = Tk()
#print(font.families()) # print list of what's available
root.title("Serial Connection Program")
self.mainFrame = Frame(root)
self.mainFrame.pack()
def_font=font.Font(family='Times')
self.portLabel = Label(self.mainFrame, text="Port1: ", font=def_font)
self.portLabel.pack()
my_font=font.Font(family='Arial')
self.portLabel = Label(self.mainFrame, text="Port2: ", font=my_font)
self.portLabel.pack()
root.mainloop()
win = Window()
我在 Raspbian OS 中遇到了类似的问题。
我将“代码粗体”更改为“代码粗体”并且它起作用了。 所以对你来说,也许可以尝试改变 Times -> times。
我在 Linux 中遇到了同样的问题。 由于 Linux 中的字体受到更多限制,因此您必须使用font.families()
列出系统中所有可用的字体,然后从列表中选择所需的字体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.