
李兴球Python简易tkinter播放器
"""
tkinter界面的pygame混音器程序.py
这个程序用tkinter界面制作了一个有4个按钮的简易播放器。
"""
import pygame
from tkinter import *
def play():
pygame.mixer.music.load('c:/华语群星 - 浏阳河+回娘家+红彩妹妹 (平四版).wav')
pygame.mixer.music.play()
def pause():
"""暂停播放音乐"""
pygame.mixer.music.pause()
def unpause():
"""取消暂停播放音乐"""
pygame.mixer.music.unpause()
def sound():
"""播放声音效果"""
pygame.mixer.Sound.play(sound_effect)
pygame.mixer.init() # 混音器初始化
sound_effect = pygame.mixer.Sound('c:/卓依婷-迎春花.wav')
root = Tk()
root.config(bg='yellow')
root.title('tkinter界面pygame混音器播放音乐程序')
root.geometry('180x160')
myframe = Frame(root)
myframe.config(bg='cyan')
myframe.pack()
mylabel = Label(myframe, text="Pygame混音器")
mylabel.pack()
button1 = Button(myframe, text=" 播 放 ", command=play, width=15)
button1.pack(pady = 5)
button2 = Button(myframe, text=" 音 效 ", command=sound, width=15)
button2.pack(pady = 5)
button3 = Button(myframe, text="继续..", command=unpause, width=15)
button3.pack(pady = 5)
button4 = Button(myframe, text=" 暂 停 ", command=pause, width=15)
button4.pack(pady = 5)
root.mainloop()