문제

I am working on a progress bar that keeps track of a certain function in pygame.

The following code causes a loop that I must force quit. And I can not figure our my error. Any help would be great.

from Tkinter import *
import ttk
import sys
import pygame

myGui = Tk()

myGui.title("Progress Bar")
myGui.geometry("400x200+200+300")

value_progress = StringVar()

pygame.mixer.init()
pygame.mixer.music.load("/home/david/Documents/aaa.mp3")
pygame.mixer.music.play()


def position():
    global value_progress
    while pygame.mixer.music.get_busy() == True: 
        value_progress.set(float(pygame.mixer.music.get_pos()))


b = Button(myGui, text="Start", )
b.pack()


p = ttk.Progressbar(myGui, variable=value_progress,
                    mode='determinate', length=350,
                    maximum= 512920)
p.pack()

I call the function from the shell. and then it stalls and does not come out of it.

This is only the progress bar portion of my work. However, it causes the program to crash every time.

도움이 되었습니까?

해결책

Do not loop. Instead try following code:

def position():
    global value_progress
    if pygame.mixer.music.get_busy():
        value_progress.set(float(pygame.mixer.music.get_pos()))
        myGui.after(100, position)

Tk.after(ms, f) call f after specified ms millisecond.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top