-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathcommands.py
108 lines (83 loc) · 3.04 KB
/
commands.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# encoding: utf8
import pathlib
from tkinter import messagebox
import pygubu
PROJECT_PATH = pathlib.Path(__file__).parent
PROJECT_UI = PROJECT_PATH / "commands.ui"
class Myapp:
def __init__(self, master=None):
self.builder = builder = pygubu.Builder()
builder.add_resource_path(PROJECT_PATH)
builder.add_from_file(PROJECT_UI)
self.mainwindow = builder.get_object("mainwindow", master)
builder.connect_callbacks(self)
self.set_scrollbars()
def run(self):
self.mainwindow.mainloop()
def on_button_clicked(self):
messagebox.showinfo(
"From callback", "Button clicked !!", parent=self.mainwindow
)
def validate_number(self, p):
print("On validate number")
value = str(p)
return value == "" or value.isnumeric()
def entry_invalid(self):
messagebox.showinfo(
"Title", "Invalid entry input", parent=self.mainwindow
)
def radiobutton_command(self):
messagebox.showinfo(
"Title", "Radiobutton command", parent=self.mainwindow
)
def checkbutton_command(self):
messagebox.showinfo(
"Title", "Checkbutton command", parent=self.mainwindow
)
def on_scale1_changed(self, event):
print(event)
label = self.builder.get_object("scale1label")
scale = self.builder.get_object("scale1")
label.configure(text=scale.get())
def on_scale2_changed(self, event):
print(event)
label = self.builder.get_object("scale2label")
scale = self.builder.get_object("scale2")
label.configure(text=int(scale.get()))
def set_scrollbars(self):
sb1 = self.builder.get_object("scrollbar_1")
sb2 = self.builder.get_object("scrollbar_2")
sb1.set(0.0, 0.20)
sb2.set(0.0, 0.20)
def on_scrollbar1_changed(self, *args):
label = self.builder.get_object("scrollbar1label")
label.configure(text=repr(args))
def on_scrollbar2_changed(self, *args):
label = self.builder.get_object("scrollbar2label")
label.configure(text=repr(args))
def on_spinbox_cmd(self):
def showmessage():
messagebox.showinfo("Title", "Spinbox command")
self.mainwindow.after_idle(showmessage)
def on_combobox_validate(self, p):
value = str(p)
return value == "" or value.isnumeric()
def on_combobox_invalid(self, p):
messagebox.showinfo(
"Title", f"Invalid combobox input: {p}", parent=self.mainwindow
)
def on_combobox_postcmd(self):
messagebox.showinfo(
"Title", "Combobox postcommand", parent=self.mainwindow
)
def on_menuitem_clicked(self, itemid):
messagebox.showinfo(
"Title", f'Menu item "{itemid}" was clicked', parent=self.mainwindow
)
def on_menuitem2_clicked(self):
messagebox.showinfo(
"Title", "Callback on_menuitem2_clicked", parent=self.mainwindow
)
if __name__ == "__main__":
app = Myapp()
app.run()