图形界面+声音播放

import pygame.mixer
from tkinter import *

sounds = pygame.mixer
sounds.init()

def wait_finish(channel):
    while channel.get_busy():
        pass

def button_click1():
    s = sounds.Sound("chimes.wav")
    s.play()
    #wait_finish(s.play())
    print("button click")
    rigthTimes.set(rigthTimes.get() + 1)

def button_click2():
    s = sounds.Sound("chimes.wav")
    s.play()
    #wait_finish(s.play())
    print("button click")


app = Tk()
app.title("Your tkinter application")
app.geometry('300x100+200+100')
rigthTimes = IntVar()
rigthTimes.set(0)

labelTitle = Label(app,text = "When you are ready,click on the buttons",height = 3)
labelTitle.pack()

label1 = Label(app,textvariable = rigthTimes)
label1.pack(side = 'left')
b1 = Button(app,text = "Right",width = 10,command = button_click1)
b1.pack(side = 'left',padx = 10,pady = 10)

label2 = Label(app,textvariable = rigthTimes)
label2.pack(side = 'right')
b2 = Button(app,text = "Wrong",width = 10,command = button_click2)
b2.pack(side = 'right',padx = 10,pady = 10)
app.mainloop()
原文地址:https://www.cnblogs.com/liuyang92/p/7407357.html