Created
December 12, 2021 04:20
-
-
Save Neko288/8cc21b903ebb0576454cb88180c2be16 to your computer and use it in GitHub Desktop.
キーボードピアノ。a,s,d,f,g,h,j,k,がドレミファソラシドにあてはめられてる。音声データが必要。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter | |
from tkinter import * | |
import pygame | |
import time | |
win = tkinter.Tk() | |
win.title("Keyboard_PIANO") | |
win.geometry('300x100') | |
#make welcome label | |
label = tkinter.Label( | |
win, | |
font = ("Lucida Sans Unicode", 14), | |
text = "Simple Keyboard piano." ) | |
label.place(x = 10, y = 30,) | |
buffer = StringVar() | |
buffer.set('') | |
def print_key(event): | |
key = event.keysym | |
if key == 'a': | |
doremi_in_def = r'PIANO\DO.mp3' | |
if key == 's': | |
doremi_in_def = r'PIANO\soud\RE.mp3' | |
if key == 'd': | |
doremi_in_def = r'PIANO\soud\MI.mp3' | |
if key == 'f': | |
doremi_in_def = r'PIANO\soud\FA.mp3' | |
if key == 'g': | |
doremi_in_def = r'PIANO\soud\SO.mp3' | |
if key == 'h': | |
doremi_in_def = r'PIANO\soud\RA.mp3' | |
if key == 'j': | |
doremi_in_def = r'PIANO\soud\SHI.mp3' | |
if key == 'k': | |
doremi_in_def = r'PIANO\soud\DO(8).mp3' | |
pygame.mixer.init() #初期化 | |
pygame.mixer.music.load(doremi_in_def) #読み込み | |
pygame.mixer.music.play(1) #再生 | |
Label(win, text = '').pack() | |
a = Label(win, textvariable = buffer) | |
a.pack() | |
a.bind('<Any-KeyPress>', print_key) | |
a.focus_set() | |
win.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment