Python 我想播放一首歌曲,同时创建一个tkinter窗口来控制歌曲

Python 我想播放一首歌曲,同时创建一个tkinter窗口来控制歌曲,python,tkinter,pygame,mixer,Python,Tkinter,Pygame,Mixer,这是我正在使用的代码。整个代码都在一个函数中 mixing = pygame.mixer.music.play with mixing(1) as song_is_playing: print(song_is_playing) def stop_btn_pressed(): stop() song_root.destroy() song_root = Tk() son

这是我正在使用的代码。整个代码都在一个函数中

    mixing = pygame.mixer.music.play
    with mixing(1) as song_is_playing:
        print(song_is_playing)

        def stop_btn_pressed():
            stop()
            song_root.destroy()
        song_root = Tk()
        song_root.title("Enter Password")
        song_root.geometry("350x200")
        song_root.config(bg="ghostwhite")
        song_frame1 = Frame(song_root, pady=40, bg="ghostwhite")
        song_frame1.pack()
        song_pause_btn = Button(song_frame1, border=2, text="Pause", 
command=pause)
        song_pause_btn.pack()
        song_btn_stop = Button(song_frame1, text="stop", 
 command=stop_btn_pressed, padx=55, bg="ghostwhite", activebackground="lightcoral")
        song_btn_stop.pack()
        song_btn_unpause = Button(song_frame1, text="Unpause", command=unpause, padx=55,
                              bg="ghostwhite", activebackground="lightcoral")
        song_btn_unpause.pack()
        song_root.mainloop()
并且得到了一个错误

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/Jarvis/testing.py", line 60, in 
<module>
    play_songs(songs)
  File "C:/Users/user/PycharmProjects/Jarvis/testing.py", line 36, in 
play_songs
    with mixing(1) as song_is_playing:
AttributeError: __enter__
回溯(最近一次呼叫最后一次):
文件“C:/Users/user/PycharmProjects/Jarvis/testing.py”,第60行,在
播放歌曲(歌曲)
文件“C:/Users/user/PycharmProjects/Jarvis/testing.py”,第36行,在
放歌
随着歌曲的播放,混音(1):
AttributeError:\u输入__

请帮助我解决此错误…我为什么会出现此错误?

什么是
混合(1)
?并非所有对象都可以与
一起使用
。看来混音
做不到这一点。它需要方法
\uuuuuuuuuuuu()
\uuuuuuu()
作为
上下文管理器来工作。看见