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()

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...