所以我正在创建一个钢琴程序,当在tkinter gui界面上按下按钮时播放声音。当我将按钮放在我想要的位置时。钢琴的黑键位于白键后面。 Image Link
如何才能使黑键位于白键顶部。
以下代码
from tkinter import *
import winsound
Gui=Tk()
Gui.title("Piano")
Gui.geometry("400x400")
def PianoF():
winsound.PlaySound("PianoF.wav",winsound.SND_ASYNC)
def PianoGb():
winsound.PlaySound("PianoGb.wav",winsound.SND_ASYNC)
def PianoG():
winsound.PlaySound("PianoG.wav",winsound.SND_ASYNC)
def PianoAb():
winsound.PlaySound("PianoAb.wav",winsound.SND_ASYNC)
def PianoA():
winsound.PlaySound("PianoA.wav",winsound.SND_ASYNC)
def PianoBb():
winsound.PlaySound("PianoBb.wav",winsound.SND_ASYNC)
def PianoB():
winsound.PlaySound("PianoB.wav",winsound.SND_ASYNC)
def PianoC():
winsound.PlaySound("PianoC.wav",winsound.SND_ASYNC)
def PianoDb():
winsound.PlaySound("PianoDb.wav",winsound.SND_ASYNC)
def PianoD():
winsound.PlaySound("PianoD.wav",winsound.SND_ASYNC)
def PianoEb():
winsound.PlaySound("PianoEb.wav",winsound.SND_ASYNC)
def PianoE():
winsound.PlaySound("PianoE.wav",winsound.SND_ASYNC)
FNote=Button(Gui,height=15,width=6,bg='white',command=PianoF)
GbNote=Button(Gui,height=9,width=5,bg='black',command=PianoGb)
GNote=Button(Gui,height=15,width=6,bg='white',command=PianoG)
AbNote=Button(Gui,height=9,width=5,bg='black',command=PianoAb)
ANote=Button(Gui,height=15,width=6,bg='white',command=PianoA)
BbNote=Button(Gui,height=9,width=5,bg='black',command=PianoBb)
BNote=Button(Gui,height=15,width=6,bg='white',command=PianoB)
CNote=Button(Gui,height=15,width=6,bg='white',command=PianoC)
DbNote=Button(Gui,height=9,width=5,bg='black',command=PianoDb)
DNote=Button(Gui,height=15,width=6,bg='white',command=PianoD)
EbNote=Button(Gui,height=9,width=5,bg='black',command=PianoEb)
ENote=Button(Gui,height=15,width=6,bg='white',command=PianoE)
GbNote.place(x=28,y=0)
AbNote.place(x=84,y=0)
BbNote.place(x=140,y=0)
DbNote.place(x=252,y=0)
EbNote.place(x=308,y=0)
FNote.place(x=0,y=0)
GNote.place(x=56,y=0)
ANote.place(x=112,y=0)
BNote.place(x=168,y=0)
CNote.place(x=224,y=0)
DNote.place(x=280,y=0)
ENote.place(x=336,y=0)
答案 0 :(得分:1)
for w in (ANote, BNote, CNote, DNote, ENote, FNote, GNote):
w.lower()
使用列表而不是那种类型的名称会更好。