问题
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