python-3.x - 如何在 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 英寸树莓派显示器上看到。
先感谢您!
解决方案
按照 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
参考:
- pmw 文档
- Pmw 函数- 你会在
logicalfont()
这里找到它,以及它需要什么参数。 Pmw.ScrolledText()
- 它需要一个text_font
kwarg。
推荐阅读
- javascript - 无论我在其中输入什么数据,纹理都是黑色的
- python - 如何从无关嵌套中清除 Python 列表?
- arrays - toArray() 的替代方案?
- kotlin - 如何在带有 kotlin 的 Retrofit 2.6.0 协程中正确使用暂停乐趣
- python - Python网络抓取日期时间并替换url中的字符串日期
- image-processing - 有没有办法在实时中将图像叠加在一个人身上?
- python - 为每个股票数据框使用 for 循环创建累积回报列时出错
- c++ - 有没有办法降低程序的时间复杂度?
- java - 如何使用 XML 配置使用 SimpleTriggerFactoryBean 将 repeatInterval 设置为 24 小时
- node.js - 运行“npm start”时无法旁加载 Office 加载项