Visitar URL original
Tkinter ::: Radiobutton class is not working properly based on type of value supplied to it · Issue #101005 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20230127120439/https://github.com/python/cpython/issues/101005
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter ::: Radiobutton class is not working properly based on type of value supplied to it #101005

Open
sangram11 opened this issue Jan 13, 2023 · 0 comments

Comments

@sangram11
Copy link

sangram11 commented Jan 13, 2023 •

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()`

image

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()`

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant