【问题标题】:Changing the background of tkinter checkbutton更改 tkinter checkbutton 的背景
【发布时间】:2020-10-21 22:49:46
【问题描述】:

我正在编写一个黑色背景和白色前景的程序。 一切(条目、标签、按钮)都可以正常工作。但是当我制作checkbutton 时,我也想用黑色bg 和白色fg 来制作它。我不知道为什么,但是 bg="black" 不会将指示器背景(您单击的那个小框)更改为黑色。而且我看不到checkbutton的状态。

checkbox is on, but I can't see it

只有当我按下左键移动光标时,我才能看到它的状态:

我该如何解决这个问题?谢谢。

检查按钮代码:

self.encryptCheckButton = Checkbutton(self.root, text="Encrypt sended files?",
                                              variable=self.encryptFile,
                                              onvalue=1, offvalue=0,
                                              bg="black", fg="white",
                                              activebackground="black",
                                              activeforeground="white")

【问题讨论】:

标签: python python-3.x tkinter


【解决方案1】:

这是因为,正如@Saad 所说,activeforeground 参数基本上是在鼠标悬停Checkbutton 上时生效,而不是在您打开它时生效。

如果你想要你想要的效果,你需要使用selecttcolor。这将在您选择它时将其设置为黑色。

完整代码:

self.encryptCheckButton = Checkbutton(self.root, text="Encrypt sended files?",
                                              variable=self.encryptFile,
                                              onvalue=1, offvalue=0,
                                              bg="white", selectcolor = "black")

如果这不适合你,试试这个:

self.encryptCheckButton = Checkbutton(self.root, text="Encrypt sended files?",
                                              variable=self.encryptFile,
                                              onvalue=1, offvalue=0,
                                              bg="black", selectcolor = "white")

希望这会有所帮助!

【讨论】:

  • 谢谢,这对我有帮助,我刚刚将 selectcolor 设置为灰色。
猜你喜欢
  • 2016-09-10
  • 2020-05-04
  • 2015-05-16
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多