Answers for "how do you get the value from a tkinter radiobutton example"

5

tkinter radiobutton

from tkinter import *

root = Tk()

i = IntVar() #Basically Links Any Radiobutton With The Variable=i.
r1 = Radiobutton(root, text="option 1", value=1, variable=i)
r2 = Radiobutton(root, text="option 2", value=2, variable=i)
#
"""
If both values where equal, when one of the buttons
are pressed all buttons would be pressed.
If a button is pressed its value is true, or 1.
If you want to acess the data from the
radiobuttons, use a if statment like
"""
if (i.get() ==1):
       print("you picked option1")
else:
        print("you picked option2")
        
# :)

r1.pack()
r2.pack()

root.mainloop()
Posted by: Guest on March-28-2020
-1

tkinter radio button get value

def Yobidasi1 ():    def func1 ():        print ("resurt", Radio_Value0.get ())        if Radio_Value0.get () == 0:                print ('Fource Shutdown')                return 0        else:                print ('hibernate')                return 1    base01 = tk.Tk ()    base01.title ("Shutdown Option")    base01.geometry ("400x150")    Radio_Value0 = tk.IntVar ()    Radio_Value0.set (0)    Shutdown_Option = {0: 'Force Shutdown', 1: 'hibernate'}    tk.Label (base01, text = 'Shutdown Option'). pack ()    R_button0 = tk.Radiobutton (base01, text = Shutdown_Option [0], variable = Radio_Value0, value = 0) .pack ()    R_button1 = tk.Radiobutton (base01, text = Shutdown_Option [1], variable = Radio_Value0, value = 1) .pack ()    button4 = tk.Button (base01, text = 'Decision', command = lambda: func1 ()). pack ()
Posted by: Guest on December-17-2020

Code answers related to "how do you get the value from a tkinter radiobutton example"

Python Answers by Framework

Browse Popular Code Answers by Language