|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下:# 曲速飞跃作
from tkinter import *
import pygame
import sys
from pygame.locals import *
do_sound = pygame.mixer.Sound("do.ogg")
ri_sound = pygame.mixer.Sound("ri.ogg")
mi_sound = pygame.mixer.Sound("mi.ogg")
fa_sound = pygame.mixer.Sound("fa.ogg")
bg_size = width, height = 3, 2
screen = pygame.display .set_mode(bg_size)
pygame.display.set_caption("MUSIC")
pygame.init()
root = Tk()
def pd():
do_sound.play()
def pr():
ri_sound.play()
def pm():
mi_sound.play()
def pf():
fa_sound.play()
Button(root, text="do", width=10, command=pd)\
.grid(row=3, column=0, padx=10, pady=5)
Button(root, text="ri", width=10, command=pr)\
.grid(row=3, column=1, padx=10, pady=5)
Button(root, text="mi", width=10, command=pm)\
.grid(row=3, column=2, padx=10, pady=5)
Button(root, text="fa", width=10, command=pf)\
.grid(row=3, column=3, padx=10, pady=5)
pygame.init()
mainloop()
错误如下:Traceback (most recent call last):
File "D:\my.code\piano\piano.py", line 7, in <module>
do = pygame.mixer.music.load("do.ogg")
pygame.error: mixer not initialized
初始化下音乐播放器,代码前面加上:pygame.mixer.init()
# 曲速飞跃作
from tkinter import *
import pygame
import sys
from pygame.locals import *
pygame.mixer.init()
do_sound = pygame.mixer.Sound("do.ogg")
ri_sound = pygame.mixer.Sound("ri.ogg")
mi_sound = pygame.mixer.Sound("mi.ogg")
fa_sound = pygame.mixer.Sound("fa.ogg")
bg_size = width, height = 3, 2
screen = pygame.display .set_mode(bg_size)
pygame.display.set_caption("MUSIC")
pygame.init()
root = Tk()
def pd():
do_sound.play()
def pr():
ri_sound.play()
def pm():
mi_sound.play()
def pf():
fa_sound.play()
Button(root, text="do", width=10, command=pd)\
.grid(row=3, column=0, padx=10, pady=5)
Button(root, text="ri", width=10, command=pr)\
.grid(row=3, column=1, padx=10, pady=5)
Button(root, text="mi", width=10, command=pm)\
.grid(row=3, column=2, padx=10, pady=5)
Button(root, text="fa", width=10, command=pf)\
.grid(row=3, column=3, padx=10, pady=5)
pygame.init()
mainloop()
|
|