2

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?

Thanks

Here's the code:

    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)
user2387537
  • 361
  • 3
  • 9
  • 17
  • 1
    That is not the normal behavious of the widget. Could you post relevant code to help usto figure out where is the problem? – A. Rodas Jun 19 '13 at 19:06
  • Also when I hover over the Radiobutton's they can all be selected at the same time but when I actually select one by using my mouse only one can be selected at one time @A. Rodas – user2387537 Jun 19 '13 at 19:15
  • Your example works as expected on my box. (Linux, python 3.2, tkinter.__version__ : '$Revision: 86697 $', tkinter.ttk.__version__ '0.3.1') – FabienAndre Jun 19 '13 at 19:36
  • 1
    I'm using classes and def's so I think that's the problem of why it is doing it but I have no idea how to solve it @FabienAndre – user2387537 Jun 19 '13 at 19:38
  • might be related: [Tkinter radio button initialization bug](http://stackoverflow.com/questions/5071559) – FabienAndre Jun 19 '13 at 19:42
  • 1
    It would help if you provided a complete working example that illustrated the problem. Often, the mere exercise of creating the working example will help you see what the problem is. – Bryan Oakley Jun 19 '13 at 21:58

1 Answers1

11

Try changing var1 to self.var1, so that the variable object doesn't get garbage-collected.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685