Binding event through class #2661
-
Hi, I'm trying to bind keys to trigger a function, but my main_frame is initialized in a different class than the one where I want to bind an event, so when I press the key, nothing happens. Where I bind self.main_frame.bind("<KeyPress-1>", lambda e: yes_but_command())
self.main_frame.bind("<KeyPress-2>", lambda e: nop_but_command())
if self.question_id != 0 and self.question_id != 4:
self.main_frame.bind("<KeyPress-3>", lambda e: choice_cam_but_command())
else:
self.main_frame.unbind("<KeyPress-3>") My main class class Main(ctk.CTk):
def __init__(self):
super().__init__()
self.title("TEst")
# Interface principale
self.main_frame = ctk.CTkFrame(self)
self.main_frame.pack(expand=True, fill="x")
# Définir la taille de la fenêtre pour qu'elle occupe tout l'écran
self.geometry(f"{self.winfo_screenwidth()}x{self.winfo_screenheight()}")
self.main_frame.lift()
self.run() And when i call my other class, i send self.main_frame Thanks 🫶 |
Beta Was this translation helpful? Give feedback.
Answered by
BaptisteBodinIP
Dec 18, 2024
Replies: 1 comment
-
Finally, problem solved, I had to pass the entire instance of my main class to my other class. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
BaptisteBodinIP
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally, problem solved, I had to pass the entire instance of my main class to my other class.