簡體   English   中英

tkinter python 3如何在mac osx上設置按鈕背景顏色

[英]tkinter python 3 how to set a buttons background colour on mac osx

經過多次嘗試和谷歌搜索后,我無法弄清楚如何設置按鈕的背景顏色。 這就是我現在所擁有的。

password_button = Button(window, text="SUBMIT", width=5, command=click, bg="black").grid(row=2, column=0, sticky=W)

任何幫助,將不勝感激。

您的代碼存在一些錯誤。 首先,你應該先按下按鈕然后再按網格,否則你可以直接對它進行網格化。 在你的代碼中,你正在創建一個名為password_button的變量,但最后,你試圖從變量內部對按鈕進行網格化。 要解決此問題,您只需將grid命令移動到單獨的行,如下所示:

password_button = Button(window,
                         text="SUBMIT",
                         width=5,
                         bg="black")
password_button.grid(row=2, column=0,sticky=W)

其次,我不認為改變tk中按鈕的背景顏色是可能的,但你可以使用ttk小部件來改變按鈕的背景顏色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM