Git Product home page Git Product logo

Comments (1)

APoppe95 avatar APoppe95 commented on June 18, 2024

My current makeshift solution is to use a CTkOptionMenu that toggles between the 'normal/disabled' states via the toggle_dropdown method (see below code) - as the event bound to left click triggers on any part of the widget, which is not the case for a CTkComboBox.

This then had an issue where selecting an option would disable the menu, forcing you to click twice in order to re-enable it and re-open the dropdown menu (however, repeatedly clicking on the widget - not the dropdown menu - does not have this issue). My temporary solution to this is to reset the state of the widget to 'normal' every 0.1 seconds via the dropdown_checker() method.

As you can tell, this is not a very pretty solution, and it also does not solve the problem for a CTkComboBox either.

import customtkinter as ctk


class DummyApp(ctk.CTk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.geometry('200x100')

        self.optionbox = ctk.CTkOptionMenu(self, values=['Option A', 'Option B'])
        self.optionbox.pack(side='left')
        self.optionbox.bind('<Button-1>', lambda event: self.toggle_dropdown(event, obox=self.optionbox))

        self.dropdown_checker()

    @staticmethod
    def toggle_dropdown(event, obox: ctk.CTkOptionMenu):
        if obox.cget('state') == 'normal':
            obox.configure(state='disabled')
        elif obox.cget('state') == 'disabled':
            obox.configure(state='normal')

    def dropdown_checker(self):
        self.optionbox.configure(state='normal')
        self.after(100, self.dropdown_checker)


if __name__ == '__main__':
    app = DummyApp()
    app.mainloop()

from customtkinter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.