[Tutor] How to display radiobutton window with no buttons selected?

Alan Gauld alan.gauld at yahoo.co.uk
Sun Apr 30 10:43:02 EDT 2017


On 25/04/17 12:39, boB Stepp wrote:

>>> I wish the displayed window to initially display with no button
>>> selected.  What am I missing here?
>>
>> It looks like the empty string is special. On my (linux) system all buttons
>> appear grayed (while a selected button would be black). Any other string
>> should give the desired result, probably because every button "thinks" that
>> another button is currently selected.

There is a simple solution.
Use a hidden butrtpon to represent no selection. Here is an example:


###################
from tkinter import *

top = Tk()

rbVar = IntVar()

rb0 = Radiobutton(top, text="hidden", variable=rbVar, value=0)
rb1 = Radiobutton(top, text='one', variable=rbVar, value=1)
rb1.pack()
rb2 = Radiobutton(top, text='two', variable=rbVar, value=2)
rb2.pack()
rb3 = Radiobutton(top, text='three', variable=rbVar, value=3)
rb3.pack()

Button(top,text='reset', command=lambda : rbVar.set(0)).pack()

top.mainloop()

##################

I was going to post this last week but typing it into a
tablet with no way to test it was too much so here is
a belated option...


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list