python - 如何增加 Tk 的标签字体大小(Python)
问题描述
我想增加我的 GUI 的标签字体大小。我尝试了我在下面附加的方式。但这会引发错误。到目前为止我尝试的是下面的代码。错误是
Traceback (most recent call last):
File "C:/Users/kobinath/PycharmProjects/pythonProject4/ex.py", line 123, in <module>
style = root.Style()
File "C:\Users\kobinath\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2345, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'Style**
root = Tk()
style = root.Style()
style.configure(
"BW.TLabel",
foreground="black",
background="white",
font="Helvetica",
fontsize=12
)
tk.Label(root, text="Student ID",style="BW.TLabel").place(x=400, y=5)
解决方案
您可以在 tkinter 标签中使用 fg、bg 和字体参数,如以下代码所示:
import tkinter as tk
root = tk.Tk()
tk.Label(root, text="Student ID", fg= "black", bg="white", font=("Helvetica",12)).place(x=400, y=5)
root.mainloop()
推荐阅读
- javascript - 为什么我可以在 Node.js 命令行中创建文件,但不能在程序中创建文件?
- javascript - 简单的纯 JavaScript 图像滑块
- c - C libgit2 - 按提交列出文件
- laravel - Laravel Bootstrap 导航栏折叠
- java - Android Studio:在导入 Eclipse 项目期间找不到 com.android.tools.build:gradle:3.6.2
- react-native - 在 Cloudinary 上使用 axios 上传 React-Native imagePicker
- r - 高斯 GAM(MGCV 包)中因变量的方差估计?
- discord.js - 获取公会中的每个频道
- javascript - javascript:合并具有相同主密钥的对象
- python - 分词的时间复杂度分析