ttk Entry widget ignores font applied via style?

不羁的心 提交于 2020-01-30 08:28:25

问题


from tkinter import Tk
from tkinter.ttk import Style, Entry
import tkinter.font as tkfont

root = Tk()

font = tkfont.Font(family='Helvetica', size=30, slant='italic')
style = Style()
style.configure('Custom.TEntry', font=font, foreground='green')
entry_font = Entry(root, font=font, foreground='green')
entry_font.insert(0, 'directly configured')
entry_font.pack()
entry_style = Entry(root, style='Custom.TEntry')
entry_style.insert(0, 'styled entry')
entry_style.pack()

root.mainloop()

The first entry responds to the font whereas the second does not. Is there a way to apply the font using styles?


回答1:


from: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Entry.html

Use this option to specify the font of the text that will appear in the widget; see Section 5.4, “Type fonts”. For reasons that are unclear to the author, this option cannot be specified with a style.

guess i'll do it directly




回答2:


Yes, but you can configure the font in the tk manner:

entry_font.configure(font=('TkTextFont', 20))


来源:https://stackoverflow.com/questions/45227862/ttk-entry-widget-ignores-font-applied-via-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!