Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_RadioButtons.py
- from Tkinter import *
- import random
- import time
- root = Tk()
- root.resizable(0,0)
- root.geometry("300x100")
- canvas = Canvas(root)
- canvas.pack()
- var1=IntVar()
- var2=IntVar()
- abc='ABC'
- def sABC():
- selection="You have selected Option " + str(abc[var1.get()])
- oABC.config(text=selection)
- def s123():
- selection="You have selected Option " + str(var2.get())
- x123.config(text=selection)
- var1.set(-1) # will deselect option sABC instead of var1.deselect()
- #
- OptionBtn1=Radiobutton(canvas, text="Option A", variable=var1, value=0, command=sABC)
- OptionBtn1.grid(row=0, column=1)
- OptionBtn2=Radiobutton(canvas, text="Option B", variable=var1, value=1, command=sABC)
- OptionBtn2.grid(row=0, column=2)
- OptionBtn3=Radiobutton(canvas, text="Option C", variable=var1, value=2, command=sABC)
- OptionBtn3.grid(row=0, column=3)
- OptionBtn1=Radiobutton(canvas, text="Option 1", variable=var2, value=1, command=s123)
- OptionBtn1.grid(row=1, column=1)
- OptionBtn2=Radiobutton(canvas, text="Option 2", variable=var2, value=2, command=s123)
- OptionBtn2.grid(row=1, column=2)
- OptionBtn3=Radiobutton(canvas, text="Option 3", variable=var2, value=3, command=s123)
- OptionBtn3.grid(row=1, column=3)
- var1.set(2) # sets selection on 'C' for option sABC as default
- oABC=Label(canvas, text="Note: 'C' has been set as default")
- oABC.grid(columnspan=4, sticky=W)
- x123=Label(canvas, text="None Selected")
- x123.grid(columnspan=4, sticky=W)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement