I'm making an app in tkinter which uses the ttk.Scale widget to show the process of an mp3 song. I have a function that I want to add buttons with the names of which (the buttons) should be relied on filenames. Therefore I've made this example:

from tkinter import Tk, Button
from tkinter.filedialog import askopenfilenames
from tkinter.ttk import Scale
from threading import Timer

root = Tk()

slider = Scale(root, from_=0, to=100, orient='horizontal')
slider.pack()

# slider is continuously set to a bigger number so that it keeps going
def update_slider(num):
    slider.set(num)
    num += 1
    root.after(50, update_slider, num)


update_slider(num=0)

# this function creates buttons based on the files opened 
def add_buttons():
    # the 'X' button of this particular window slows down execution of update_slider function
    files = askopenfilenames(title='Add Buttons')
    for i in list(files):
        Button(root, text=i).pack()


button = Button(root, text='Browse', command=lambda: Timer(0.1, add_buttons).start())
button.pack()

root.mainloop()

The problem I'm facing is that when I open the askopenfilenames dialog box or when I press its 'X' button, my slider which is running continuously in the background gets stuck, and as a result doesn't show the process correctly.

Here is a picture where I hold down the 'X' button and the ttk.Scale stops moving: Holding down 'X' buttons stops execution

I've tried using threading to run the add_buttons function but the behavior of the program remains the same.

Can I edit the askopenfilenames dialog box with something similar like overrideredirect(True) so that I can make my own title bar and 'X' button and the events generated not to slow down my Scale?

Replying to:

I cannot reproduce the issue in Linux, the scale keeps moving no matter what I do with the filedialog window. So this may be an OS specific issue.

I'm aware that this problem doesn't appear on Linux. I faced the same problem with the root's close button and other Toplevels' close button, but I fixed it by replacing the title bar using overrideredirect(True).
Is there anything similar I can do with this askopenfilenames window?

0

There are 0 best solutions below