Skip to content

Commit

Permalink
Radio Button in Tkinter
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Jun 22, 2018
1 parent 9f0c4d1 commit 00fa4df
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Tkinter/radioButton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from tkinter import *

def showresult():
print("Value of v is ",v.get())

root = Tk()
v = IntVar()
Label(root, text="Choose a programming language:",justify = LEFT, padx = 20).grid(row=1)
Radiobutton(root, text="Python", padx = 20, variable=v, value=0).grid(row=2)
Radiobutton(root, text="Perl", padx = 20, variable=v, value=1).grid(row=3)

Button(root,text="Show Result",command=showresult).grid(row=4)
root.mainloop()
34 changes: 34 additions & 0 deletions Tkinter/radioButton_improved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import tkinter as tk

root = tk.Tk()

v = tk.IntVar()
v.set(1) # initializing the choice, i.e. Python

languages = [
("Python",1),
("Perl",2),
("Java",3),
("C++",4),
("C",5)
]

def ShowChoice():
print(v.get())

tk.Label(root,
text="""Choose your favourite
programming language:""",
justify = tk.LEFT,
padx = 20).pack()

for val, language in enumerate(languages):
tk.Radiobutton(root,
text=language,
padx = 20,
variable=v,
command=ShowChoice,
value=val).pack(anchor=tk.W)


root.mainloop()

0 comments on commit 00fa4df

Please sign in to comment.