Answer the question
In order to leave comments, you need to log in
Why can't PySimpleGUI output a two digit number?
I made a simple program that takes data from strings and generates a random number in their range. But if you set values above ten, then in any case it displays numbers from 1 to 9. Is this a module or code problem and how to fix it?
import PySimpleGUI as sg
import random
sg.theme("Dark Green")
x = 0
y = 0
def generate():
x = values["FROM"]
y = values["TO"]
values['OUTPUT'] = random.randint(int(x), int(y))
window['OUTPUT'].update(values['OUTPUT'])
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(random.randint(int(x), int(y)), key = 'OUTPUT')],
]
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
sg.Text is a label in which you need to specify the required field width so that all the numbers fit.
For example, for a four digit number, size=(4,1) :
[sg.Button("Generate:", key = "GENERATE"), sg.Text(random.randint(int(x), int(y)), size=(4,1), key = 'OUTPUT')],
[sg.Button("Generate:", key = "GENERATE"), sg.Text(random.randint(int(x), int(y)), key = 'OUTPUT', auto_size_text=False)],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question