-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed as not planned
Closed as not planned
Copy link
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-tkintertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
In Tkinter package Radiobutton is not working properly. It is showing different behavior based on different type of value selected for a given variable.
from tkinter import *
root = Tk()
root.geometry("300x300")
gender = StringVar() #gender variable is set as string type
male = Radiobutton(root, text = "Male", variable = gender, value = "male")
female = Radiobutton(root, text = "Female", variable = gender, value = "female")
male.pack()
female.pack()
root.mainloop()
If you run this simple piece of code, you will find all radio buttons are selected.
This is happening because gender variable is set as string type.
A user obviously doesn't want all radio buttons to be selected.
Whereas if you run this below piece of code for integer type
from tkinter import *
root = Tk()
root.geometry("300x300")
gender = IntVar() #gender variable is set as integer type
male = Radiobutton(root, text = "Male", variable = gender, value = 1)
female = Radiobutton(root, text = "Female", variable = gender, value = 2)
male.pack()
female.pack()
root.mainloop()
You will find none of the option has been selected for radio buttons. This is the actual expectation for any user. They don't want all radio buttons to be selected.
Moreover, there should be an argument in Radiobutton class to select a particular radio button out of many. This is missing.
Die4Ever
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-tkintertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error