[英]is there a way to set a default button color (on click) for tkinter?
[英]Default color of button Tkinter
默認按鈕顏色的名稱是什么? 如果您不輸入任何顏色(如 bg. 我想將我在程序中輸入的 bg 刪除為默認顏色,這樣它看起來就像一開始那樣。
謝謝!
正如@jasonharper 在評論中所寫。 由於操作系統之間的默認顏色不同,重置按鈕顏色的最簡單方法是在將其設置為其他顏色之前獲取並存儲它。 然后您可以簡單地使用此值將按鈕重置為其默認顏色。
import tkinter
root = tkinter.Tk()
button = tkinter.Button(root, text='Hello')
DEFAULT_BUTTON_COLOR = button['bg']
button['bg'] = 'blue'
button.pack()
# Somewhere in your code where you want to reset the color
button['bg'] = DEFAULT_BUTTON_COLOR
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.