6

I want to access value of selected Radiobutton and compare it with if statement but on accessing the value I am getting PY_VAR0 instead.

from tkinter import *
ComplaintForm=Tk()
typesel=StringVar()#<--variable I'm using to access value of selected Radiobutton
HighVoltage=Radiobutton(ComplaintForm,text='High Voltage Motor',value='HighVoltage',\
                      anchor=W,font='roboto 18',bg='white',variable=typesel)
HighVoltage.grid(row=5,column=1,padx=5,pady=10)

LowVoltage=Radiobutton(ComplaintForm,text='Low Voltage Motor',value='LowVoltage',\
                      anchor=W,font='roboto 18',bg='white',variable=typesel)
LowVoltage.grid(row=5,column=0,padx=5,pady=10)

print(typesel)#this is printing PY_VAR0 instead of accessing value of above Radiobuttons
mainloop()

PS: I know there are some malpractices in this code which have been introduced to keep the code minimal and problem easily understandable.

1
  • If you search for [tkinter] py_var0 on this site you will find many questions and answers that would probably tell you what you need. Commented Jul 1, 2018 at 16:20

1 Answer 1

12

You can access the value of a tkinter Variable Class BooleanVar, DoubleVar, IntVar, or StringVar like this:

my_variable = tk.StringVar()
my_variable.set('value')
print(my_variable.get())   # <-- returns and prints the value contained in my_variable

see here for more info.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.