-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsliderdemo.py
48 lines (30 loc) · 1.13 KB
/
sliderdemo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import tkinter as tk
from tkinter import ttk
# root window
root = tk.Tk()
root.geometry('300x200')
root.resizable(False, False)
root.title('Slider Demo')
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=3)
# slider current value
current_value = tk.DoubleVar()
def get_current_value():
return '{: .2f}'.format(current_value.get())
def slider_changed(event):
value_label.configure(text=get_current_value())
# label for the slider
slider_label = ttk.Label( root, text='Slider:')
slider_label.grid(column=0, row=0, sticky='w')
# slider
slider = ttk.Scale(root, from_=0, to=100, orient='horizontal',
command=slider_changed, variable=current_value)
slider.grid(column=1, row=0, sticky='we')
# current value label
current_value_label = ttk.Label(root, text='Current Value:')
current_value_label.grid(row=1, columnspan=2, sticky='n', ipadx=10, ipady=10)
# value label
# value_label = ttk.Label(root, text=get_current_value()) # text CALLS A FUNCTION!!!
value_label = ttk.Label(root, text=current_value.get()) # text CALLS A FUNCTION!!!
value_label.grid(row=2, columnspan=2, sticky='n')
root.mainloop()