Skip to content

Instantly share code, notes, and snippets.

@MrGibus
Created September 2, 2020 15:02
Show Gist options
  • Select an option

  • Save MrGibus/9f3ad86989e2c5fd064a511e937e1eed to your computer and use it in GitHub Desktop.

Select an option

Save MrGibus/9f3ad86989e2c5fd064a511e937e1eed to your computer and use it in GitHub Desktop.
Basic form, inputs and an output
import PySimpleGUI as sg
sg.theme("DarkBlue")
def deflection(l, e, i, w):
d = 5 / 384 * w * l**4 / e / i
return f'{d:0.3f}'
def main():
layout = [[sg.Text("L:"), sg.Input(key='-LENGTH-')],
[sg.Text("E:"), sg.Input(key='-E-')],
[sg.Text("I:"), sg.Input(key='-I-')],
[sg.Text("w:"), sg.Input(key='-LOAD-')],
[sg.Button('Calculate')],
[sg.Text("δ"), sg.Input(key='-OUTPUT-')]]
window = sg.Window('Simple Deflection Calculator', layout)
while True:
event, values = window.read()
print(event, values)
if event == 'Exit' or event == sg.WIN_CLOSED:
break
if event == 'Calculate':
l = float(values['-LENGTH-'])
e = float(values['-E-'])
i = float(values['-I-'])
w = float(values['-LOAD-'])
d = deflection(l, e, i, w)
print(d)
window.FindElement('-OUTPUT-').update(d)
window.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment