Skip to content

Instantly share code, notes, and snippets.

@viseshrp
Created November 1, 2021 21:10
Show Gist options
  • Save viseshrp/d80573e4bf40bf24a6ca5946675b85e3 to your computer and use it in GitHub Desktop.
Save viseshrp/d80573e4bf40bf24a6ca5946675b85e3 to your computer and use it in GitHub Desktop.
pygui.py
import PySimpleGUI as sg
def say_hi(dog_name):
return 'Hi ' + dog_name.title() + '!!'
def run_stuff(event):
# your stuff
if event == 'Show':
# Update the "output" text element to be the value of "input" element
inp = values['IN']
text = say_hi(inp)
window['OUT'].update(text)
def main():
# set theme
sg.theme('DarkAmber')
# set font
sg.set_options(font=("Arial", 22))
# All the stuff inside your window.
layout = [
[sg.Text("Enter your dog's name"), sg.InputText(key='IN')],
# [sg.Text('Click a command', font=font, justification='center', key='OUT')],
[sg.Text('Click Show to say hi here', justification='center', key='OUT')],
# [sg.Button('Come here'), sg.Button('Fetch that'), sg.Button('Eat')],
[sg.Button('Show'), sg.Button('Cancel')]
]
# Create the Window
window = sg.Window('Dog commander', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
close_events = (sg.WIN_CLOSED, 'Cancel', 'Exit');
if event in close_events: # if user closes window or clicks cancel
break
# your stuff goes here.
run_stuff(event)
window.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment