TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
10.77k stars 1.03k forks source link

Scrolling on ttk.Combobox with CTkScrollableFrame underneath #2455

Open t-poplawski opened 1 month ago

t-poplawski commented 1 month ago

Scrolling on Combobox droplist from tkinter.ttk module raises exception when there's CTkScrollableFrameunderneath.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python311\Lib\site-packages\customtkinter\windows\widgets\ctk_scrollable_frame.py", line 248, in _mouse_wheel_all
    if self.check_if_master_is_canvas(event.widget):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[user]\AppData\Local\Programs\Python\Python311\Lib\site-packages\customtkinter\windows\widgets\ctk_scrollable_frame.py", line 280, in check_if_master_is_canvas
    elif widget.master is not None:
         ^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'master

Sample code:

import tkinter as tk
import tkinter.ttk as ttk
import customtkinter as ctk

def display_combobox(root):
    sample_values = ['test' for _ in range(30)]
    combo_box = ttk.Combobox(root, values=sample_values)
    combo_box.place(anchor='center', relx=0.5, rely=0.3)

def display_scrollable(root):
    scrollabe_frame = ctk.CTkScrollableFrame(root, label_text='text', width=150)
    scrollabe_frame.place(anchor='center', relx=0.5, rely=0.6)

if __name__ == '__main__':
    root = tk.Tk()
    root.geometry('500x500')
    display_combobox(root)
    display_scrollable(root)

    root.mainloop()

image

dipeshSam commented 4 weeks ago

Either make a sample reproducible code available or checkout the following for instant solution: https://github.com/Akascape/CTkScrollableDropdown

Regards.