[英]How to determine the font being used by a ttk.Button in tkinter?
我有一個 ttk 按鈕,我想知道它的字體。 使用: my_button.cget('font')
給了我_tkinter.TclError: unknown option "-font"
。 好吧,這意味着小部件本身沒有存儲字體。 所以我嘗試用my_style.cget('font')
來查詢樣式。 然后結果是AttributeError: 'Style' object has no attribute 'cget'
。
這是一個代碼片段。 這次我嘗試直接更改字體。 我知道它是 calibri 但無法查詢:
my_style = ttk.Style()
my_style.configure('W.TButton', background='black',
font=('calibri', 10, 'bold', 'underline'), foreground='white')
print(my_style.cget('font'))
改用my_style.lookup("W.TButton", "font")
。
您還可以使用:
my_style.configure('W.TButton', 'font')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.