因此,我創建了一個鋼琴程序,在tkinter gui界面上按下按鈕時播放聲音。當我把按鈕放在我想要它們的地方時。鋼琴的黑鍵在白鍵後面。 Image Link。Python 3.5 - 在按鈕上放置按鈕
我怎樣才能讓黑鍵在白鍵上。
下面的代碼
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)
在圖像中的黑鍵是在白鍵的頂部,所以有什麼意義? – cdonts
黑鍵並不完全位於其上方,黑鍵右側的白鍵被剪下 – Imanity