tkinter 单选按钮在鼠标悬停在它上面时被选中 [英] tkinter Radiobutton gets selected when the mouse hovers over it

查看:72
本文介绍了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 单选按钮在鼠标悬停在它上面时被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆