如何在Tkinter中设置Entry的字体大小

4

我是Python的初学者,我想在Entry小部件中设置字体大小。我尝试设置参数font=("Calibri",12),但没有效果,字体大小仍然像默认值一样。

有没有什么方法可以设置它?

from Tkinter import *

root = Tk()

EntryList = []
for i in range(81):

    EntryList.append(Entry(root,font=("Calibri",12),justify="center",width=6,bg="#1E6FBA",fg="yellow",disabledbackground="#1E6FBA",disabledforeground="yellow",highlightbackground="black",highlightcolor="red",highlightthickness=1,bd=0))
    EntryList[i].grid(row=i/9,column=i%9,ipady=14)     

root.mainloop()

3
请展示你正在尝试的代码。 - Serial
我不理解它。现在它运行得很好。我只是删除了字体参数,运行了脚本,结束了脚本,按下Ctrl+Z,再次运行脚本,然后它就正常了... 无论如何,代码示例在编辑中。 - Milan Skála
4个回答

4

使用font=("Calibri 12")即可(这对我很有效)


3
from Tkinter import *

root = Tk()

EntryList = []
for i in range(81):

EntryList.append(Entry(root, font = "Helvetica 44 bold",justify="center",width=6,bg="#1E6FBA",fg="yellow",disabledbackground="#1E6FBA",disabledforeground="yellow",highlightbackground="black",highlightcolor="red",highlightthickness=1,bd=0))
EntryList[i].grid(row=i/9,column=i%9,ipady=14)     

root.mainloop()

0
你可以创建一个变量。
from Tkinter import *
import tkinter.font

root = Tk()

EntryList = []
for i in range(81):
FontOfEntryList=tkinter.font.Font(family="Calibri",size=12)
EntryList.append(Entry(root,font=FontOfEntryList,justify="center",width=6,
bg="#1E6FBA",fg="yellow",disabledbackground="#1E6FBA",disabledforeground="yellow",
highlightbackground="black",highlightcolor="red",highlightthickness=1,bd=0))
EntryList[i].grid(row=i/9,column=i%9,ipady=14)     

root.mainloop()

-4
class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
                            #---------RIGHT HERE----#
    entry1 = tk.Entry(self, font="Helvetica 20 bold", width=20)
    entry1.pack(pady=5, padx=5 )



app = project1()
app.mainloop()

1
修复代码缩进。更好的方法是,简单地解释如何在 tk.Entry() 中使用 font 参数。 - HEADLESS_0NE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接