Skip to content

Commit 75a78a1

Browse files
committed
Demo for CheckButtons and RadioButtons. Comments in ButtonApp Code
1 parent 721dcfe commit 75a78a1

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import program2 as p2
1111
import program3 as p3
1212
import program4 as p4
13+
import program5 as p5
1314

1415
def main():
1516
p1.sayhello()
1617
p2.HelloAppLaunch()
1718
p3.GreetingAppLaunch()
1819
p4.launchButtonApp()
20+
p5.launchButton2App()
1921

2022
if __name__ == '__main__':main()

src/program4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
This program demonstrates the use of button widget in tkinter
77
'''
8+
89
import tkinter as tk
910
from tkinter import ttk
1011

src/program5.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'''
2+
Created on Sep 7, 2017
3+
4+
This program includes the demonstration of
5+
Checkbuttons and Radio Buttons using Tkinter
6+
7+
@author: Aditya
8+
'''
9+
10+
import tkinter as tk
11+
from tkinter import ttk
12+
13+
class Button2App():
14+
def __init__(self, master):
15+
16+
# More advanced as compared to regular buttons
17+
# Check buttons can also store binary values
18+
self.checkbutton = ttk.Checkbutton(master, text = 'Check Me!')
19+
self.checkbutton.pack()
20+
self.label = ttk.Label(master, text = 'Ready!! Nothing has happened yet.')
21+
self.label.pack()
22+
# Tkinter variable classes
23+
# self.boolvar = tk.BooleanVar() # boolean type variable of tk
24+
# self.dblvar = tk.DoubleVar() # double type variable of tk
25+
# self.intvar = tk.IntVar() # int type variable of tk
26+
self.checkme = tk.StringVar() # string type variable of tk
27+
self.checkme.set('NULL') # set value for string type tkinter variable
28+
print('Current value of checkme variable is \'{}\''.format(self.checkme.get()))
29+
30+
# setting of binary value for check button: 1. onvaalue and 2. offvalue
31+
self.checkbutton.config(variable = self.checkme, onvalue = 'I am checked!!', offvalue = 'Waiting for someone to check me!')
32+
self.checkbutton.config(command = self.oncheckme)
33+
34+
35+
# creating another tkinter string type variable - StringVar
36+
self.papertype = tk.StringVar() # created a variable
37+
self.radiobutton1 = ttk.Radiobutton(master, text = 'Paper1', variable=self.papertype, value = 'Robotics Research')
38+
self.radiobutton1.config(command = self.onselectradio)
39+
self.radiobutton1.pack()
40+
self.radiobutton2 = ttk.Radiobutton(master, text = 'Paper2', variable=self.papertype, value = 'Solid Mechanics Research')
41+
self.radiobutton2.config(command = self.onselectradio)
42+
self.radiobutton2.pack()
43+
self.radiobutton3 = ttk.Radiobutton(master, text = 'Paper3', variable=self.papertype, value = 'Biology Research')
44+
self.radiobutton3.config(command = self.onselectradio)
45+
self.radiobutton3.pack()
46+
self.radiobutton4 = ttk.Radiobutton(master, text = 'Paper4', variable=self.papertype, value = 'SPAM Research')
47+
self.radiobutton4.config(command = self.onselectradio)
48+
self.radiobutton4.pack()
49+
self.radiobutton5 = ttk.Radiobutton(master, text = 'Change Checkme text', variable=self.papertype, value = 'Radio Checkme Selected')
50+
self.radiobutton5.pack()
51+
self.radiobutton5.config(command = self.onradiobuttonselect)
52+
53+
def oncheckme(self): # callback function for checkbutton
54+
txt = self.checkme.get() # get the value of stringVar checkme
55+
self.label.config(text = txt) # display the value of checkme in label
56+
57+
def onradiobuttonselect(self):
58+
self.checkbutton.config(textvariable = self.papertype)
59+
60+
def onselectradio(self):
61+
self.label.config(text = self.papertype.get())
62+
63+
def launchButton2App():
64+
root = tk.Tk()
65+
Button2App(root)
66+
tk.mainloop()
67+
68+
def test():
69+
launchButton2App()
70+
71+
if __name__ == '__main__':
72+
test()

0 commit comments

Comments
 (0)