【发布时间】:2019-03-31 00:52:14
【问题描述】:
首先,感谢您尝试帮助我。我目前正在使用 tkinter 编写我的第一个 GUI,并且我尝试创建带有大字体的按钮,因为我想为视障人士创建一个程序。可悲的是,我有两个问题我自己无法通过互联网解决..
这是我的代码的相关部分:(对不起德语变量)
import tkinter
from tkinter import *
from tkinter import font
import tkinter.messagebox
class Oberflaeche(tkinter.Frame):
def __init__(self, master=None):
tkinter.Frame.__init__(self, master)
self.pack()
MyFont = font.Font(family='times', size=50)
self.close_window = tkinter.Button(self, font=MyFont, text="Programm \nbeenden", command=self.close_window, bg="white", height = 3, width = 18, bd=3, relief="solid")
self.close_window.pack()
def close_window(self):
root.destroy()
root = tkinter.Tk()
root.title("Prototyp MVP")
root.minsize(width=300, height=300)
root.configure(background='white')
oberflaeche = Oberflaeche(master=root)
oberflaeche.mainloop()
当我尝试更改字体时,tkFont.Font 不起作用。有错误: NameError: 名称 'tkFont' 未定义
这就是我尝试 font.Font 的原因。但无论我如何更改字体系列或类型,它总是看起来很糟糕和像素化......
Picture of the failed Button
我正在使用 python 3.5.5、Ubuntu 16.04 和 tk 8.6.8。
【问题讨论】:
标签: python user-interface tkinter fonts