闲不住的老杨 发表于 2023-2-25 01:24:35

Python实战之梦幻钢琴小游戏的实现

导语

今天来给大家写一款界面化的(Tkinter)电子钢琴小程序。
音乐是声音的艺术,它通过人们的听觉,来传达思想情感、表现社会生活。但它与舞蹈、绘画不同的呈现形式不同,舞蹈是通过肢体语言,绘画是通过色彩和线条来体现艺术形象。而音乐不是一种具象的形态,它需要通过人们的内心去感受,去理解。
因此,在音乐的学习中,有很多抽象的概念对孩子来说非常难以理解,例如律动、放松、呼吸等。其实,这些看似“只可意会不可言传”的概念,以及一些手指技巧,都可以通过一些形象的比喻,向孩子们说明问题,这不仅能提高孩子们的学习兴趣,并且还能使这些知识在脑海里留下深刻印象。
今天这款电子钢琴小程序不仅可以学到小知识还能边玩儿边锻炼手速鸭~爱了没?

一、环境准备

1)运行环境
开发环境:Python3、Pycharm社区版、tkinter,部分自带的模块安装Python即可使用。
2)模块安装
第三方库的安装方式如下:
一般安装:pip install +模块名
镜像源安装:pip install -i https://pypi.douban.com/simple/+模块名
模块安装问题可以详细的找我给大家讲一下的哈,之前其实也有的文章写了几个点的。

二、代码展示

1)导入模块
import winsound

from tkinter import *2)主程序
def doone():
        for i in range(1,11):
                i=i*500
                winsound.Beep(i,500)
def submit():#读取乐谱并播放的函数
        music = list(map(str,u.get()))#        print(music)        print(p.get())
        order =[,,,]
        match =['0','1','2','3','4','5','6','7','8','9']
        char =[ 'A','B','C','D']
        n = 1
        j=0
        k=0
        m=0
        time1 =
        order1 =
        order11 =
        orderm =
        for i in range(len(music)):
                if music == '/':
                        n=n+1
                if i==0:
                        if music == '0' and music == '.' and music == '5':
                                time1=0.5
                                j=j+1
                        t=0
                        while t<10:
                                if music == match and music == '/':
                                        time1=t
                                        j=j+1
                                t=t+1
                else:
                        if music == '0' :
                                time1=0.5
                                j=j+1
                        for tp in range(1,9):
                                if (music == match and music == '/' ):
                                        time1=tp
                                        j=j+1
                        for tn in range(0,4):
                                if music == char:
                                        order1=tn
                                        m=m+1
                        for tt in range(1,9):
                                if music == match and ( music == 'A' or music == 'B' or music == 'C' or music == 'D') :
                                        order11=tt
                                        k=k+1
        print(n)
        l=0
        while l< n:
                time1=time1*int(p.get())
                orderm=order]-1]
                time1=int(time1)#                print("时间,字母,顺序,音律以此为:")                print(time1,   order1,order11,orderm)
                l=l+1
        l=0
        while l <n:#                print(orderm,time1)
                winsound.Beep(orderm,time1)
                l=l+1
#图形界面
root = Tk()
root.title("电子钢琴简易版")
frame = Frame(root)
frame.pack(padx=8, pady=8, ipadx=4)
lab1 = Label(frame, text="请输入乐谱:")
lab1.grid(row=0, column=0, padx=5, pady=5, sticky=W)
#u = StringVar()
#ent1 = Entry(frame, textvariable=u)
#ent1.grid(row=0, column=1, sticky='ew', columnspan=2)
lab2 = Label(frame, text="请输入每个音节代表的时间(单位ms):")
lab2.grid(row=1, column=0, padx=5, pady=5, sticky=W)
p = StringVar()
ent2 = Entry(frame, textvariable=p)
ent2.grid(row=1, column=1, sticky='ew', columnspan=2)
button = Button(frame, text="确认", command=submit, default='active')
button.grid(row=2, column=1)
button2 = Button(frame, text="退出", command=quit)
button2.grid(row=2, column=2, padx=5, pady=5)
button3 = Button(frame, text="第一题播放",command=doone)
button3.grid(row=2, column=0)
三、效果展示

1)运行界面
https://img.jbzj.com/file_images/article/202302/202322482546856.png
2)小程序截图
https://img.jbzj.com/file_images/article/202302/202322482546857.png
以上就是Python实战之梦幻钢琴小游戏的实现的详细内容,更多关于Python梦幻钢琴游戏的资料请关注脚本之家其它相关文章!

来源:https://www.jb51.net/article/276288.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: Python实战之梦幻钢琴小游戏的实现