2017年10月10日 星期二

Tkinter 電子音樂-Button



from tkinter import *
import winsound
import time
C  = 262
Db = 277
D  = 294
Eb = 311
E  = 330
F  = 349
Gb = 370
G  = 392
Ab = 415
A  = 440
Bb = 466
B  = 494
hC  = 523
t = 250
root = Tk() # create tkinter window

def play_Do () :
    winsound.Beep(C, 2*t)
def play_Re () :
    winsound.Beep(D, 2*t)
def play_Mi () :
    winsound.Beep(E, 2*t)
def play_Fa () :
    winsound.Beep(F, 2*t)
def play_Sol () :
    winsound.Beep(G, 2*t)
def play_La () :
    winsound.Beep(A, 2*t)
def play_Si () :
    winsound.Beep(B, 2*t)
def play_Hi_Do () :
    winsound.Beep(hC, 2*t)

 
 
button1 = Button(root, text = 'Play_Do', command = play_Do)
button2 = Button(root, text = 'Play_Re', command = play_Re)
button3 = Button(root, text = 'Play_Mi', command = play_Mi)
button4 = Button(root, text = 'Play_Fa', command = play_Fa)
button5 = Button(root, text = 'Play_Sol', command = play_Sol)
button6 = Button(root, text = 'Play_La', command = play_La)
button7 = Button(root, text = 'Play_Si', command = play_Si)
button8 = Button(root, text = 'Play_Hi_do', command = play_Hi_Do)
button1.pack()
button2.pack()
button3.pack()
button4.pack()
button5.pack()
button6.pack()
button7.pack()
button8.pack()

root.mainloop()

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...