TomSchimansky / CustomTkinter

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

AttributeError: 'bind_all' is not allowed #1142

Open IshanJ25 opened 1 year ago

IshanJ25 commented 1 year ago

Hi, I made an application for my school project, which was running stable on v4.5.9 and now I ungraded my installed package to latest version, v5.0.5. Now when I run the application it throws an error:

File "D:\path\to\env\folder\lib\site-packages\customtkinter\windows\widgets\core_widget_classes\ctk_base_class.py", line 254, in bind_all
    raise AttributeError("'bind_all' is not allowed, could result in undefined behavior")
AttributeError: 'bind_all' is not allowed, could result in undefined behavior

here is the code where I require to set bind_all to show a "Caps lock" symbol in a user-login form:

    capslock_status_label = ctk.CTkButton(password_frame, image=capslock_img, width=55, height=55, corner_radius=20,
                                          fg_color=color.black_3, bg_color=color.black_2, text="",
                                          hover=False)
    # bind this with caps lock key press
    capslock_status_label.bind_all('<Key>', lambda key: key_pressed())
    capslock_status_label.bind('<Destroy>', lambda _: capslock_status_label.unbind_all('<Key>'))

    if my_functions.is_capslock_on():
        capslock_status_label.place(x=gap_bw_toggle_btn_and_frame, rely=0.5, anchor='w')

  # # # # # # #
  # Code reduced for brevity
  # # # # # # #

    def key_pressed():

        if my_functions.is_capslock_on():
            capslock_status_label.place(x=gap_bw_toggle_btn_and_frame, rely=0.5, anchor='w')
        else:
            capslock_status_label.place_forget()

I suggest there be a flag variable set to False be default, which allows the bind_all method to be used when a user explicitly sets that particular variable as True

Cathnan commented 1 year ago

+1 for this. I wanted to embed a pandas Dataframe using padastable. Unfortunately I can't because bind_all is not allowed. I think having it disallowed by default, but making use of it possible if explicitly requested would be great.

ElectricCandlelight commented 1 year ago

Why can't you just use bind? Not sure if bind_class works in ctk but might be worth having a look at.

Cathnan commented 1 year ago

Why can't you just use bind? Not sure if bind_class works in ctk but might be worth having a look at.

In my case, I can't use it, because bind_all is used somewhere in the code of pandastable itself. The code I wrote, in which I wanted to use it, didn't use bind at all. I simply placed the pandastable widget, and on start it threw the error IshanJ25 described.

paulinhok14 commented 10 months ago

Hello @Cathnan , did you solve it?

As same as you, I'm trying to embed a pandas dataframe in Table object from pandastable but I'm having the same error msg:

AttributeError: 'bind_all' is not allowed, could result in undefined behavior

The only parameters I've passed for creation is a root tkinter Frame as parent and my dataframe.

Any ideas on it?

Thank you

Cathnan commented 10 months ago

Hello @Cathnan , did you solve it?

As same as you, I'm trying to embed a pandas dataframe in Table object from pandastable but I'm having the same error msg:

AttributeError: 'bind_all' is not allowed, could result in undefined behavior

The only parameters I've passed for creation is a root tkinter Frame as parent and my dataframe.

Any ideas on it?

Thank you

I was lucky enough that I didn't need big parts of pandas table. What I needed was more a front end to display the content of a data frame. I was able to implement everything I needed with tksheet. If you're dependent on pandas table you could look into tkinter themes. Of course you wouldn't have the convenience of ctk that way.