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 单选按钮在鼠标悬停在它上面时被选中


基础教程推荐
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 筛选NumPy数组 2022-01-01