Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

how to toggle different buttons with same function on CustomTkinter

$
0
0

I'm trying to create a grid of buttons that toogle or at least change once pressed.But I couldn't manage to diferenciate each button to change their parameters through self.button.config()Or even develop a toggle function that handle all buttons

I cut down some parts for better reading of my code, its build over one of the samples in customtkinter's documentation

import customtkintercustomtkinter.set_appearance_mode("System")  # Modes: "System" (standard), "Dark", "Light"customtkinter.set_default_color_theme("dark-blue")  # Themes: "blue" (standard), "green", "dark-blue"class App(customtkinter.CTk):    def __init__(self):        super().__init__()        self.dezenas_frame = customtkinter.CTkFrame(self, width=30, corner_radius=0)        self.dezenas_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")        self.dezenas_frame.grid_rowconfigure(4, weight=1)        self.logo_label = customtkinter.CTkLabel(self.dezenas_frame, text="text text!",                                                 font=customtkinter.CTkFont(size=10, weight="bold"))        self.logo_label.grid(row=0, column=0, padx=15, pady=(10, 10))        c_r = 1        c_c = 1        for cnt in range(1, 61):            self.button = customtkinter.CTkButton(self.dezenas_frame, text=cnt, width=40,                                                command=self.toggleState)            self.button.grid(row=c_r, column=c_c, padx=1, pady=1)            if c_c == 10: c_c = 0; c_r += 1            c_c += 1    def toggleState(self):        self.config(self, state='something')if __name__ == "__main__":    app = App()    app.mainloop()

Also tried differentiate each button (button_01, button_02, ... button_60) with tk but still got stuck

 self.button_01 = tk.Button(self.right_frame, text="01", relief="raised", command=self.togg) self.button_01.grid(row=0, column=0, padx=5, pady=5) self.button_02 = tk.Button(self.right_frame, text="02", relief="raised", command=self.togg) self.button_02.grid(row=0, column=1, padx=5, pady=5)...self.button_60 = tk.Button(self.right_frame, text="60", relief="raised", command=self.togg)self.button_60.grid(row=5, column=9, padx=5, pady=5)

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>