F
F
FIRSTNAME LASTNAME2019-08-20 19:14:44
Python
FIRSTNAME LASTNAME, 2019-08-20 19:14:44

What is the reason for the program's departure?

I apologize in advance - I'm still a newbie and I definitely don't know what to do.
I am writing an mp3 player. Everything seems to be going great. The play button in the middle calls the function of the same name:

def play():
    global audiofile, mp3_lst, mp3_patch, \
        plitem, title, song_time, lng, secs,\
        mins, hours, div, div2, time_to_move
    mp3_patch = mp3_lst[plitem]
    audiofile = mutagen.File(dir + "\\" + mp3_patch)
    title = mp3_patch[0:-4]
    name_text.config(text=title)
    lng = int(audiofile.info.length)
    if lng >= 60:
        div = divmod(lng, 60)
        mins = div[0]
        secs = div[1]
    else:
        mins = 0
        secs = lng
    if mins >= 60:
        div2 = divmod(mins, 60)
        hours = div2[0]
        mins = div2[1]
    else:
        hours = 0
    song_time = timedelta(minutes=mins,
                          seconds=secs,
                          milliseconds=hours)
    time1_label.config(text=song_time)

And everything works, right up to adding the following fragment to the end of the function code, which is designed to move the circle along the playback timeline:
time_to_move = (300-5-1) / lng
    while time2_label['text'] != time1_label['text']:
        time.sleep(1)
        canvas.move(play_circle,
                    time_to_move,
                    0)

Only a white screen is displayed, and after 5 seconds python stops responding. What could be the reason?5d5c1c6bdd556360912269.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-08-20
@true_pelmeshek

GUI events are handled by an infinite loop that starts when you call mainloop()it. It cannot be stopped or the application will hang. And the loop whileand the call time.sleep(1)do just that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question