summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorSimeon Simeonov2025-12-23 09:59:50 +0100
committerSimeon Simeonov2025-12-23 09:59:50 +0100
commita29c4509a316c0c77450b6fa74b96f036b0f0821 (patch)
tree13babfe7a0fba24c7df609c909b81ab70f4092ec /app.py
parent8ad11db860898dcfc9269f2b84df7e301a6e8e5c (diff)
Add structure
Diffstat (limited to 'app.py')
-rw-r--r--app.py75
1 files changed, 0 insertions, 75 deletions
diff --git a/app.py b/app.py
deleted file mode 100644
index cf4bc1d..0000000
--- a/app.py
+++ /dev/null
@@ -1,75 +0,0 @@
1"""Simple score counter for two teams"""
2
3import toga
4from toga.style.pack import COLUMN, ROW
5
6
7class ScoreCounter(toga.App):
8 """The main ScoreCounter application"""
9
10 def startup(self):
11 """startup entry point"""
12 self.score_team1 = 0
13 self.score_team2 = 0
14
15 main_box = toga.Box(direction=COLUMN)
16
17 self.score_label1 = toga.Label(
18 f'Team1: {self.score_team1}', margin=(0, 5), color='red'
19 )
20 self.score_label2 = toga.Label(
21 f'Team2: {self.score_team2}', margin=(0, 5), color='blue'
22 )
23 self.separator_label = toga.Label(' - ', margin=(0, 10))
24
25 score_box = toga.Box(direction=ROW, margin=5)
26 score_box.add(self.score_label1)
27 score_box.add(self.separator_label)
28 score_box.add(self.score_label2)
29
30 button_clear = toga.Button(
31 'Clear', on_press=self.cb_clear, margin=(20, 5, 5)
32 )
33 button_team1 = toga.Button(
34 'Team 1 (+1)', on_press=self.cb_score_team1, margin=(20, 5, 5)
35 )
36 button_team1.style.background_color = 'red'
37 button_team2 = toga.Button(
38 'Team 2 (+1)', on_press=self.cb_score_team2, margin=5
39 )
40 button_team2.style.background_color = 'blue'
41
42 main_box.add(score_box)
43 main_box.add(button_team1)
44 main_box.add(button_team2)
45 main_box.add(button_clear)
46
47 self.main_window = toga.MainWindow(title=self.formal_name)
48 self.main_window.content = main_box
49 self.main_window.show()
50
51 def cb_clear(self, _widget):
52 """Clear on press callback"""
53 self.score_team1 = 0
54 self.score_team2 = 0
55 self.refresh()
56
57 def cb_score_team1(self, _widget):
58 """Team1 on press callback"""
59 self.score_team1 += 1
60 self.refresh()
61
62 def cb_score_team2(self, _widget):
63 """Team 2 on press callback"""
64 self.score_team2 += 1
65 self.refresh()
66
67 def refresh(self):
68 """Refreshes the score labels"""
69 self.score_label1.text = f'Team1: {self.score_team1}'
70 self.score_label2.text = f'Team2: {self.score_team2}'
71
72
73def main():
74 """main entry point"""
75 return ScoreCounter()