PySimpleGUI/DemoPrograms/Demo_Button_Click.py

31 lines
908 B
Python
Raw Normal View History

2018-09-27 20:24:09 +00:00
#!/usr/bin/env python
import winsound
import sys
import PySimpleGUI as sg
2018-10-21 17:18:05 +00:00
if not sys.platform.startswith('win'):
sg.popup_error('Sorry, you gotta be on Windows')
sys.exit(0)
2018-09-27 20:24:09 +00:00
2019-11-27 22:19:31 +00:00
# .WAV files that contain your click sounds. Put full path if not in your application's folder
click_sound = r'ButtonClick.wav'
click_sound1 = r'ButtonClick1.wav'
2019-11-27 22:19:31 +00:00
sg.change_look_and_feel('Dark Blue 3') # because gray windows are boring
2019-11-27 22:19:31 +00:00
# Your window's layout
layout = [ [sg.Text('Click a button to hear a click')],
[sg.Button('Click'), sg.Button('Another Click')]]
# Create your Window
window = sg.Window("Button Click", layout)
2019-11-27 22:19:31 +00:00
while True: # The Event Loops
event, values = window.read()
if event is None:
break
2019-11-27 22:19:31 +00:00
if event == 'Click':
winsound.PlaySound(click_sound, 1)
elif event == 'Another Click':
winsound.PlaySound(click_sound1, 1)
window.close()