"""Simple score counter for two teams""" import toga from toga.style.pack import COLUMN, ROW class ScoreCounter(toga.App): """The main ScoreCounter application""" def startup(self): """startup entry point""" self.score_team1 = 0 self.score_team2 = 0 main_box = toga.Box(direction=COLUMN) self.score_label1 = toga.Label( f'Team1: {self.score_team1}', margin=(0, 5), color='red' ) self.score_label2 = toga.Label( f'Team2: {self.score_team2}', margin=(0, 5), color='blue' ) self.separator_label = toga.Label(' - ', margin=(0, 10)) score_box = toga.Box(direction=ROW, margin=5) score_box.add(self.score_label1) score_box.add(self.separator_label) score_box.add(self.score_label2) button_clear = toga.Button( 'Clear', on_press=self.cb_clear, margin=(20, 5, 5) ) button_team1 = toga.Button( 'Team 1 (+1)', on_press=self.cb_score_team1, margin=(20, 5, 5) ) button_team1.style.background_color = 'red' button_team2 = toga.Button( 'Team 2 (+1)', on_press=self.cb_score_team2, margin=5 ) button_team2.style.background_color = 'blue' main_box.add(score_box) main_box.add(button_team1) main_box.add(button_team2) main_box.add(button_clear) self.main_window = toga.MainWindow(title=self.formal_name) self.main_window.content = main_box self.main_window.show() def cb_clear(self, _widget): """Clear on press callback""" self.score_team1 = 0 self.score_team2 = 0 self.refresh() def cb_score_team1(self, _widget): """Team1 on press callback""" self.score_team1 += 1 self.refresh() def cb_score_team2(self, _widget): """Team 2 on press callback""" self.score_team2 += 1 self.refresh() def refresh(self): """Refreshes the score labels""" self.score_label1.text = f'Team1: {self.score_team1}' self.score_label2.text = f'Team2: {self.score_team2}' def main(): """main entry point""" return ScoreCounter()