如何在spyder上用python制作音乐播放器

时间:2020-08-09 06:47:08

标签: python pygame

我正在尝试在spyder上使用python制作音乐播放器,但它一直告诉我未安装pygame,因此我陷入了这个问题。我已经通过cmd提示符安装了pygame,但仍然无法正常工作。这是代码:

"""Import Modules"""
import pygame
import tkinter as tkr

"""Create Windows"""
player = tkr.Tk()

"""Edit Window"""
player.title("Audio Player")
player.geometry("205x40")

"""Get Song"""
file = "Wha wha.mp3"

"""Action Event"""
def Play():
    pygame.init()
    pygame.mixer.init()
    pygame.mixer.music.load(file)
    pygame.mixer.music.play()
    
def ExitPlayer():
    pygame.mixer.music.stop()

"""Register Buttons"""
button1 = tkr.Button (player,width=6,height=3,text="Play",command=Play)
button1.pack(fill="x")
button2 = tkr.Button (player,width=6,height=3,text="Stop",command=ExitPlayer)
button2.pack(fill="x")

"""Song Name"""
label1 = tkr.LabelFrame(player, text="Song Name")
label1.pack(fill="both", expand="yes")
contents1 = tkr.label(label1,text=file)
contents1.pack()

"""Activate"""
player.mainloop()

0 个答案:

没有答案