changed combobox and optionemnu command to only get triggered by manual selection #440

This commit is contained in:
Tom Schimansky 2022-09-15 18:46:24 +02:00
parent 66f9fa2386
commit c16c891115
5 changed files with 8 additions and 9 deletions

View File

@ -33,8 +33,7 @@ pip3 install customtkinter
The **official** documentation can be found in the Wiki Tab here: The **official** documentation can be found in the Wiki Tab here:
### **--> [Documentation](https://github.com/TomSchimansky/CustomTkinter/wiki)**. **--> [Documentation](https://github.com/TomSchimansky/CustomTkinter/wiki)**.
## Example Program ## Example Program
To test customtkinter you can try this simple example with only a single button: To test customtkinter you can try this simple example with only a single button:

View File

@ -268,7 +268,7 @@ class CTkComboBox(CTkBaseClass):
outline=ThemeManager.single_color(self.button_color, self._appearance_mode), outline=ThemeManager.single_color(self.button_color, self._appearance_mode),
fill=ThemeManager.single_color(self.button_color, self._appearance_mode)) fill=ThemeManager.single_color(self.button_color, self._appearance_mode))
def set(self, value: str, from_variable_callback: bool = False): def set(self, value: str, from_variable_callback: bool = False, from_dropdown_menu_callback: bool = False):
self.current_value = value self.current_value = value
if self.state == "readonly": if self.state == "readonly":
@ -280,7 +280,7 @@ class CTkComboBox(CTkBaseClass):
self.entry.delete(0, tkinter.END) self.entry.delete(0, tkinter.END)
self.entry.insert(0, self.current_value) self.entry.insert(0, self.current_value)
if not from_variable_callback: if from_dropdown_menu_callback:
if self.command is not None: if self.command is not None:
self.command(self.current_value) self.command(self.current_value)

View File

@ -279,7 +279,7 @@ class CTkOptionMenu(CTkBaseClass):
if not self.variable_callback_blocked: if not self.variable_callback_blocked:
self.set(self.variable.get(), from_variable_callback=True) self.set(self.variable.get(), from_variable_callback=True)
def set(self, value: str, from_variable_callback: bool = False): def set(self, value: str, from_variable_callback: bool = False, from_dropdown_menu_callback: bool = False):
self.current_value = value self.current_value = value
self.text_label.configure(text=self.current_value) self.text_label.configure(text=self.current_value)
@ -289,7 +289,7 @@ class CTkOptionMenu(CTkBaseClass):
self.variable.set(self.current_value) self.variable.set(self.current_value)
self.variable_callback_blocked = False self.variable_callback_blocked = False
if not from_variable_callback: if from_dropdown_menu_callback:
if self.command is not None: if self.command is not None:
self.command(self.current_value) self.command(self.current_value)

View File

@ -96,7 +96,7 @@ class DropdownMenu(tkinter.Menu):
def button_callback(self, value): def button_callback(self, value):
if self.command is not None: if self.command is not None:
self.command(value) self.command(value, from_dropdown_menu_callback=True)
def configure(self, **kwargs): def configure(self, **kwargs):
if "values" in kwargs: if "values" in kwargs:

View File

@ -27,10 +27,10 @@ optionmenu_2 = customtkinter.CTkOptionMenu(app, variable=variable, values=countr
dynamic_resizing=False) dynamic_resizing=False)
optionmenu_2.pack(pady=20, padx=10) optionmenu_2.pack(pady=20, padx=10)
combobox_tk = ttk.Combobox(app, values=countries) combobox_tk = ttk.Combobox(app, values=countries, textvariable=variable)
combobox_tk.pack(pady=10, padx=10) combobox_tk.pack(pady=10, padx=10)
combobox_1 = customtkinter.CTkComboBox(app, variable=None, values=countries, command=select_callback, width=300) combobox_1 = customtkinter.CTkComboBox(app, variable=variable, values=countries, command=select_callback, width=300)
combobox_1.pack(pady=20, padx=10) combobox_1.pack(pady=20, padx=10)
def set_new_scaling(scaling): def set_new_scaling(scaling):