簡體   English   中英

在 Tkinter 中使用 selectimage 時如何從屏幕上隱藏簡單的 Checkbutton?

[英]How to hide simple Checkbutton from screen when using selectimage in Tkinter?

我正在制作一個 GUI 應用程序,我想在其中使用復選框( Checkbutton中的 Checkbutton)。 我不太喜歡簡單復選按鈕的設計(而且我不想使用 ttk),所以我決定使用來自互聯網的圖像。 我有一個 selected.png 和一個 deselected.png。 將它們分配給我的 Checkbutton 時,它們會出現,但原來的簡單復選框不會消失。

這是 window 的屏幕截圖,因此您可以更好地理解我在說什么。

...
deselect_image = PhotoImage(file='deselected.png')
select_image = PhotoImage(file='selected.png')

classic = Checkbutton(window, font = ('Courier', 10), image = deselect_image, text = " Classic theme", selectimage = select_image, compound = 'left', variable = theme_classic, bg = "#FFFFFF", command = lambda: select_theme("classic"))
classic.grid(row = 5, column = 1, sticky = "w")

blue = Checkbutton(window, font = ('Courier', 10), image = deselect_image, text = " Dark Blue theme", selectimage = select_image, compound = 'left', variable = theme_blue, bg = "#FFFFFF", command = lambda: select_theme("blue"))
blue.grid(row = 6, column = 1, sticky = "w")

black = Checkbutton(window, font = ('Courier', 10), image = deselect_image, text = " Black theme", selectimage = select_image, compound = 'left', variable = theme_black, bg = "#FFFFFF", command = lambda: select_theme("black"))
black.grid(row = 7, column = 1, sticky = "w")
...

我認為我們可以通過傳遞參數indicatoron=False來隱藏復選框,但這會在分別未選中和選中時給你一個凸起/凹陷的效果。 如果您不想要那種凸起/凹陷的效果,那么將borderwith 的值更改為 0

像這樣的東西

Checkbutton(window, font = ('Courier', 10), image = deselect_image, 
            text = " Classic theme", selectimage = select_image, 
            compound = 'left', variable = theme_classic, bg = "#FFFFFF", 
            command = lambda: select_theme("classic"), 
            indicatoron=False, borderwidth=0)

查看Checkbutton的所有選項。

暫無
暫無

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

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