Jishnu Vijayan Jishnu Vijayan - 1 year ago 64
Python Question

Python Tkinter - Can radio button values be floating point numbers?

I'm writing a program where I've to select 15 values out of 6 radio buttons each, and each value that should be returned is a floating point value. On using Tkinter Radiobutton:

r155 = Radiobutton(master,text=" ",variable=j, value=1.10)

It returns the value after ignoring the values after decimal point, here j.get() returns 1.

Similarly, for:

r144 = Radiobutton(master,text=" ",variable=i, value=0.91)

i.get() return 0. Is it possible to get floating point numbers?

Answer Source

Yes, your variables can take floating point values. However, for that, you need to define i and j to be DoubleVars rather than IntVars

Even though it is not shown, I believe that somewhere earlier than your radio button definitions you have the lines:

i = IntVar()
j = IntVar()

These must be changed to:

i = DoubleVar()
j = DoubleVar()


Also, note that if your radio buttons belong to the same group, they should use the same variable (i.e., the argument variable=i should be used for both buttons):

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download