首页 > 解决方案 > 如何在 tkinter 中设置字体大小

问题描述

希望到目前为止我们每个人都度过了美好的圣诞节!

在这段代码中,我需要一些关于我的字体大小的帮助:

import Pmw
from tkinter import * 
import tkinter.font 

root = Tk()
root.title("Dashboard") 
root.attributes('-zoomed', True)

filename = "SMS.txt"
        
top = Frame(root); top.pack(side='top')
text = Pmw.ScrolledText(top,
       borderframe=5, 
       vscrollmode='dynamic', 
       hscrollmode='dynamic',
       labelpos='n', 
       label_text='Todays Data %s' % filename,
       text_width=120, 
       text_height=35,
       text_wrap='none',
       text_padx=14,
       text_pady=14,
       )
text.pack()
text.insert('end', open(filename,'r').read())

root.mainloop()

我希望文本区域中的字体很大,这样可以在我的 3 英寸树莓派显示器上看到。

脚本运行: 在此处输入图像描述

先感谢您!

标签: python-3.xuser-interfacetkinter

解决方案


按照 Pmw 文档中的说明,您似乎想要执行以下操作:

font_size = 20  # Edit this value here
my_font = Pmw.logicalfont("Fixed", font_size)
text = Pmw.ScrolledText(text_font=my_font)  # Along with the other kwargs you'd need

参考:


推荐阅读