tkinter Radiobutton gets selected when the mouse hovers over it(tkinter 单选按钮在鼠标悬停在它上面时被选中)
问题描述
我在 tkinter 中使用单选按钮,我可以很好地选择它们,但是当鼠标悬停在其中一个选项上时,它会被选中,而无需我实际单击鼠标左键.我已经研究过将单选按钮的状态更改为禁用,但显然我无法选择禁用的选项,而且我还使用了取消选择和选择方法,它们不会阻止鼠标选择当它悬停在它上面时的选项.有没有办法在我用鼠标点击它之前停止鼠标选择选项?
I'm using Radiobuttons in tkinter and I can select them fine but when the mouse hovers over one of the options it gets selected without me actually clicking the left button on the mouse. I've looked at changing the state of the Radiobutton to disabled but obviously then I wouldn't be able to select the option that is disabled and I've also used the deselect and select method and they don't stop the mouse from selecting the option when it's hovering over it. Is there a way to stop the mouse selecting the option before I click it by using my mouse?
谢谢
代码如下:
var1 = IntVar()
self.u1r1 = Radiobutton(self, text = 'Passed', value = 1, variable = var1)
self.u1r1.grid(row = 0, column = 0, sticky = W)
self.u1r2 = Radiobutton(self, text = 'Not Passed', value = 2, variable = var1)
self.u1r2.grid(row = 0, column = 0, sticky = W, padx = 60)
self.u1r3 = Radiobutton(self, text = 'Waiting', value = 3, variable = var1)
self.u1r3.grid(row = 0, column = 0, sticky = W, padx = 145)
推荐答案
试试把var1改成self.var1,这样变量对象就不会得到垃圾了-收集.
Try changing var1 to self.var1, so that the variable object doesn't get garbage-collected.
这篇关于tkinter 单选按钮在鼠标悬停在它上面时被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:tkinter 单选按钮在鼠标悬停在它上面时被选中
基础教程推荐
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
