Replies: 2 comments 1 reply
-
@MrDerekib Could you please have sample code (either in Tkinter or CustomTkinter) for your requirements? Further more information about your desired result would be helpful. Like the following:
Also, in your description:
After selection, the next one gets enabled, but what about the first one? Does the first one also go disabled or it remains enabled to change the selected value again? Regards. |
Beta Was this translation helpful? Give feedback.
-
@MrDerekib Here is sample implementation of the facility you want: from tkinter import Event
from customtkinter import CTk, CTkFrame, CTkComboBox
from typing import Callable, Any
class CombosFrame(CTkFrame):
def __init__(self, master: CTk, callback: Callable[[str, tuple[int, int]], Any] = None, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.callback = callback
self._active: CTkComboBox = None
self.items: list[CTkComboBox] = []
def _on_click(self, event: Event):
self._active = event.widget.master
def _on_select(self, value: str):
self._active_next()
if self.callback:
grid_info = self._active.grid_info()
self.callback(value, (grid_info["row"], grid_info["column"]))
def _active_next(self):
index = self.items.index(self._active) + 1
combo: CTkComboBox = self.items[index if index < len(self.items) else index - 1]
combo.configure(state="normal")
def fill(self, items: list[list[CTkComboBox]]):
"""Takes list of columns of CTkComboboxes."""
for col, combo_cols in enumerate(items):
for row, combobox in enumerate(combo_cols):
combobox.grid(row=row, column=col, padx=10, pady=10)
combobox._canvas.bind("<Button-1>", self._on_click)
combobox.configure(command=self._on_select)
self.items.append(combobox)
# Enabling first one
items[0][0].configure(state="normal")
if __name__ == "__main__":
def on_select(*data):
print(data)
app = CTk()
frame = CombosFrame(app, callback=on_select)
frame.pack(fill="both", expand=True, padx=20, pady=40)
sample_values = ("Sample1", "Sample2", "Sample3")
combos = [[CTkComboBox(frame, values=sample_values, state="disabled") for _ in range(5)] for _ in range(3)]
frame.fill(combos)
app.mainloop() As in your example code, only one column is used, to do so, replace Regards. |
Beta Was this translation helpful? Give feedback.
-
I've done an internal tool with tkinter and I'm migrating to CustomTkinter for best looking and it's a think I can solve by my own. Will appreciate some help.
The "app" fills an excel with data, nothing fancy.
I have some CTkComboBox in it, the first one is enabled (state= "normal") and the other ones are disabled (state="disabled").
When You pick an option of the first combobox, the next will be enabled an the rest remains disabled... you pick some value on the 2nd and the third will be enabled...
I have done this feature with tkinter but i can't with CustomTkinter.
Any idea / method to solve it?
I've have success with a button in CustomTkinter but it's not the finest experience
Beta Was this translation helpful? Give feedback.
All reactions