Tkinter scale gets stuck each time a function is called Tkinter scale gets stuck each time a function is called tkinter tkinter

Tkinter scale gets stuck each time a function is called


Look at this code:

import tkinter as tkdef config_buttons():    # Get the `text` of the first button    starting_value = int(buttons[0].cget("text")) + 1    # Iterate over all of the buttons    for i, button in enumerate(buttons, start=starting_value):        # Change the button's `text` and `command` atributes        button.config(text=i, command=lambda i=i:print("Clicked %i"%i))root = tk.Tk()buttons = []add_button = tk.Button(root, text="+1 on all buttons", command=config_buttons)add_button.pack()for i in range(50):    button = tk.Button(root, text=i, command=lambda i=i:print("Clicked %i"%i))    button.pack()    buttons.append(button)root.mainloop()

When the add_button buttons is pressed, I iterate over all of the buttons and change their text and command attributes. As I am not creating new buttons, the function runs very fast.

You can implement something similar in your code. Basically, avoid creating new buttons and just update the ones you already have on the screen.