Skip to content

Commit a6ad1e6

Browse files
committed
App for Controlling Progressbar and Scalebar
1 parent 612f2ce commit a6ad1e6

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

src/program8.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'''
2+
Created on Oct 24, 2017
3+
4+
@author: Aditya
5+
6+
Program for demonstrating use of Progress bar and Scale Widget in tkinter
7+
8+
'''
9+
10+
import tkinter as tk
11+
from tkinter import ttk
12+
13+
14+
class ControlledProgress:
15+
def __init__(self, master):
16+
ttk.Label(master, text = "PROGRESS CONTROL").pack()
17+
18+
# Inderterminant Progressbar
19+
ttk.Label(master, text = 'Inderterminant Progress').pack()
20+
self.prgrsbr_indtr = ttk.Progressbar(master, orient = tk.HORIZONTAL, length = 300, mode = 'indeterminate')
21+
self.prgrsbr_indtr.pack()
22+
self.checkpbi = tk.StringVar()
23+
self.checkpbi.set("Start")
24+
25+
# Button
26+
self.btn1 = ttk.Button(master, text = "{} Inderterminant Progress Bar".format(self.checkpbi.get()), command = self.btn1cmd)
27+
self.btn1.pack()
28+
29+
# Derterminant progress
30+
ttk.Label(master, text = 'Derterminant Progress').pack()
31+
self.prgrsbr_dtr = ttk.Progressbar(master, orient=tk.HORIZONTAL, length = 300, mode = 'determinate')
32+
self.prgrsbr_dtr.pack()
33+
self.prgrsbr_dtr.config(maximum = 10.0, value = 2.0) # notice both these properties have float values
34+
35+
# Button
36+
ttk.Button(master, text = 'Reset Progress Bar to zero', command = self.resetProgressBarVal).pack()
37+
38+
# Button
39+
ttk.Button(master, text = 'Increase Progress Bar by 2', command = self.shift2ProgressBarVal).pack()
40+
41+
# create double variable
42+
self.prgrsBrVal = tk.DoubleVar()
43+
44+
self.prgrsbr_dtr.config(variable = self.prgrsBrVal) # set variable property of progressbar to look at DoubleVar()
45+
46+
# Scale widget
47+
self.scalebar = ttk.Scale(master, orient = tk.HORIZONTAL, length = 400, variable=self.prgrsBrVal, from_ = 0.0, to= 10.0)
48+
self.scalebar.pack()
49+
50+
# Label to display current value of scalebar
51+
ttk.Label(master, text = "Current value of Progress Bar is as below:").pack()
52+
self.scalebar_label = ttk.Label(master, textvariable = self.prgrsBrVal)
53+
self.scalebar_label.pack()
54+
55+
def btn1cmd(self):
56+
if self.checkpbi.get() == "Start":
57+
self.checkpbi.set("Stop")
58+
self.btn1.config(text = "{} Inderterminant Progress Bar".format(self.checkpbi.get()))
59+
self.prgrsbr_indtr.start()
60+
else:
61+
self.checkpbi.set("Start")
62+
self.btn1.config(text = "{} Inderterminant Progress Bar".format(self.checkpbi.get()))
63+
self.prgrsbr_indtr.stop()
64+
65+
66+
def resetProgressBarVal(self):
67+
#self.prgrsbr_dtr.config(value = 0.0)
68+
self.prgrsBrVal.set(0.0)
69+
70+
def shift2ProgressBarVal(self):
71+
self.prgrsbr_dtr.step(2)
72+
73+
def ControlledPorgressApp():
74+
root = tk.Tk()
75+
ControlledProgress(root)
76+
tk.mainloop()
77+
78+
def test():
79+
ControlledPorgressApp()
80+
81+
if __name__ == '__main__': test()

0 commit comments

Comments
 (0)