【问题标题】:Python tkinter button font is getting pixelated in bigger sizesPython tkinter 按钮字体越来越像素化
【发布时间】: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


    【解决方案1】:

    我正在使用 Spyder(python 3.6) 这是结果; i.hizliresim.com/6NgZlW.jpg 也许是因为版本? 实际上您的程序运行成功,我没有更改我在我的电脑上尝试过的任何代码,结果很完美(Win10 Spyder(Python 3.6)。)

    【讨论】:

    • 我正在使用 jupyter 笔记本。也许这就是问题所在?我会试试spyder。谢谢:)
    【解决方案2】:

    我也习惯了 Jupyter notebook,我正在尝试使用 VS Code,一切都运行良好。我建议您尝试缩放并告诉我它对您有用吗?

    Scaling of Tkinter GUI in 4k (3840*2160) resolution

    结果

    Jupyter

    VS 代码

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 2016-03-05
      相关资源
      最近更新 更多