Answer the question
In order to leave comments, you need to log in
How to make a button in PySimpleGUI work?
I made a simple window with a number generator in pysimplegui and everything works except for the Generate button. I do not understand why the text does not take the desired value.
import PySimpleGUI as sg
import random
sg.theme("Dark Green")
num = ""
def generate():
x = values["FROM"]
y = values["TO"]
num = random.randint(int(x), int(y))
return num
layout = [
[sg.Text("From:"), sg.Input(size = (5, 1), enable_events = True, key = ("FROM"))],
[sg.Text("To:"), sg.Input(size = (5, 1), enable_events = True, key = ("TO"))],
[sg.Button("Generate:", key = ("GENERATE")), sg.Text(num)],
]
window = sg.Window("Random numbers", layout, size = (150, 100))
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == "GENERATE":
generate()
window.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question