From 42a440a47bb235d220d43fe9678c966abaca82d2 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 11 Feb 2024 01:20:29 +0100 Subject: [PATCH] checkbox func --- src/gui_main.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/gui_main.py b/src/gui_main.py index 90b2b07..79ada7a 100644 --- a/src/gui_main.py +++ b/src/gui_main.py @@ -80,7 +80,25 @@ def run_installer(download_folder_tmp, col_isDark): widget_args.pop('text', None) return CTkComboBox(master=master, **widget_args) elif widget_class == CTkCheckBox: - return CTkCheckBox(master=master, **widget_args) + # Extract command_on and command_off, defaulting to None if not present + command_on = widget_args.pop('command_on', None) + command_off = widget_args.pop('command_off', None) + + # Define the single command function + def single_command(): + if widget_var.get() == 1 and command_on: + command_on() + elif widget_var.get() == 0 and command_off: + command_off() + + # Create IntVar for CTkCheckBox + widget_var = IntVar() + + # Create CTkCheckBox with remaining arguments + checkbox = CTkCheckBox(master=master, variable=widget_var, **widget_args) + checkbox.bind("", lambda event: single_command()) + + return checkbox else: return spec(master=master) @@ -115,15 +133,18 @@ def run_installer(download_folder_tmp, col_isDark): tab_combobox.set(list(tabs.keys())[previous_tab_index]) visible_widgets = create_widgets_for_current_tab() - def switch_to_install_tab(): - switch_to_tab("Tab3") + def func1(): + print("ON") + + def func2(): + print("OFF") tabs = { "Tab1": [ (CTkComboBox, {"text": "Language", "values": ["London", "Britan", "New York"]}), (CTkComboBox, {"text": "Theme", "values": [f"System {'(Dark)' if col_isDark else '(Light)'}", "Light", "Dark"]}), - (CTkCheckBox, {"text": f"Force {'dark' if col_isDark else 'light'} mode"}), - (CTkButton, {"text": "Install", "command": switch_to_install_tab}), + (CTkCheckBox, {"text": f"Force {'dark' if col_isDark else 'light'} mode", "command_on": func1, "command_off": func2}), + (CTkButton, {"text": "Install", "command": start_install}), (CTkButton, {"text": "Customise", "command": switch_to_next_tab}), ], "Tab2": [