首页 > 解决方案 > 我想播放一首歌,同时创建一个控制歌曲的 tkinter 窗口

问题描述

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

    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__

帮我解决这个错误...为什么我会收到这个错误?

标签: pythontkinterpygamemixer

解决方案


推荐阅读