SNC92
SNC92

Reputation: 11

CTkComboBox Dropdown Closes Immediately for Large Lists

I'm using CustomTkinter to create a GUI in Python, and I'm facing an issue with the CTkComboBox widget. When I populate the ComboBox with a large list of items, the dropdown menu shows the options, but it closes automatically unless I keep holding down the left mouse button.

Here's a minimal example that reproduces the problem:

import customtkinter as ctk

# List of values for the ComboBox
options = ['alpha_1', 'alpha_2', 'alpha_3', 'A_1', 'A_2', 'A_3', 'y_1', 'y_2', 'y_2p', 'y_3', 
           'v_Phi', 'cutoff', 'M [GeV]', 'm_y', 're_tau_charged_leptons', 'im_tau_charged_leptons',
           're_tau_neutrinos', 'im_tau_neutrinos', 'm_electron [GeV]', 'm_muon [GeV]', 'm_tau [GeV]',
           'chi_electron', 'chi_muon', 'chi_tau', 'chi_charge_lepton_sector', 'm_h [GeV]', 
           'Dm_21 [eV^2]', 'Dm_31 [eV^2]', 'chi_Dm21', 'chi_Dm31', 'mv_1 [eV]', 'mv_2 [eV]', 
           'mv_3 [eV]', 'mN_1 [GeV]', 'mN_2 [GeV]', 'mN_3 [GeV]', 'Sigma [eV]', 'Jarlskog_invariant',
           'PMNSphase', 'PMNSs12_SQ', 'PMNSs23_SQ', 'PMNSs13_SQ', 'chi_PMNSs12SQ', 'chi_PMNSs23SQ', 
           'chi_PMNSs13SQ', 'chi_PMNSphase', '|VPMNS_11|', '|VPMNS_12|', '|VPMNS_13|', '|VPMNS_21|', 
           '|VPMNS_22|', '|VPMNS_23|', '|VPMNS_31|', '|VPMNS_32|', '|VPMNS_33|', 'meff_ve [eV]', 
           'meff_vmu [eV]', 'meff_vtau [eV]', 'm_ee [eV]', 'chi_neutrino_sector', 'BR_muTOegamma']

# Create the application window
class App(ctk.CTk):
    def __init__(self):
        super().__init__()

        self.title("CustomTkinter ComboBox Example")
        self.geometry("400x300")

        # Create a CTkComboBox with the provided list of values
        self.combobox = ctk.CTkComboBox(self, values=options)
        self.combobox.grid(row=0, column=0, padx=20, pady=20)

        # Optionally, set an initial value
        self.combobox.set("Select an option")

# Run the application
if __name__ == "__main__":
    app = App()
    app.mainloop()

Edit: I noticed that the issue seems to be related exclusively to the length of the dropdown menu. When the menu is displayed and it doesn't touch the bottom of the screen, it works "fine" and stays open. However, when the menu reaches the bottom of the screen, it collapses immediately after clicking. I discovered this behavior while testing on a larger screen where the dropdown didn’t collapse, but it still requires careful window positioning. So I guess one possible solution could be incorporating the scroll feature for the dropdown, which would prevent the menu from extending too far. However, I'm not sure how to implement this in CustomTkinter.

I'm using Python3.12.6 on Ubuntu 22.04.5 LTS

Any help or suggestions would be appreciated.

Upvotes: 1

Views: 103

Answers (0)

Related Questions