0

所以我想在 python 3.7 中编写一个音乐播放器,它可以播放音乐并按比例显示我在歌曲中的位置。我还希望我可以通过单击scale.

但它给了我错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "", line 1705, in __call__
    return self.func(*args)
  File "", line 786, in __init__
    assert group is None, "group argument must be None for now"
AssertionError: group argument must be None for now

它可能不是干净的程序希望你能看到有什么问题或修复它谢谢;)

from pygame import mixer
from tkinter import *
import os
from mutagen.mp3 import MP3
from threading import Thread
import time

r=Tk()

a= 'musicfile.mp3'

filedata = os.path.splitext(a)

audio = MP3(a)
lenghtsound = audio.info.length

mixer.init()

mins, secs = divmod(lenghtsound, 60)
mins = round(mins)
secs = round(secs)
timeformat = '0:{:02d}:{:02d}'.format(mins, secs)
print(timeformat)

def get_sec(time_str):
    """Get Seconds from time."""
    h, m, s = time_str.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s)

问题从这里开始,是关于“def run(self)”函数的问题,但我不知道我的代码边界上的这个小圆盘符号到底是什么,当我按下它时,会出现一个巨大的代码“threading.py”我想这是关于threeading的解释,但我不明白那里的一些东西。请帮助:(

f = get_sec(timeformat)
x = 0
n = 0
ab = True 

class timer(Thread):
    def run(self):
        global x, f, ab
        while ab:
            if x == n:
                c = n-x
                f = f-c
                x = n
            x = x + 1
            de.set(x)
            print(x)
            if x >= f:
                ab = False
            mins, secs = divmod(x, 60)
            mins = round(mins)
            secs = round(secs)
            songdurationleft = '{:02d}:{:02d}'.format(mins, secs)
            abc2['text']='playing'+songdurationleft
            time.sleep(1)

class setppos(Thread):
    def run(self):
        print('hi')
        global n
        b = de.get()
        mixer.music.set_pos(b)
        n = b

def gg():
    mixer.music.load(a)
    mixer.music.set_volume(0.2)
    mixer.music.play()
    T1 = timer(daemon=True)
    T2 = setppos(daemon=True)
    T1.start()
    T2.start()

abc = Button(r,command=gg,text='play/start threads')
abc.pack()
abc1 = Label(r,text=timeformat)
abc1.pack(side=LEFT)
abc2 = Label(r,text='song duration:')
abc2.pack(side=RIGHT)

de=Scale(r,from_=0,to_=f,orient=HORIZONTAL,sliderlength=10,length=600,tickinterval=5,showvalue=0,command
=setppos)
de.set(0)
de.pack()

r.mainloop()
4

0 回答 0