Reputation: 11
How do I get it to use low_end
and high_end
in the range as integers
#!/usr/bin/python3
import random
import PySimpleGUI as sg
sg.theme('DarkBlue17')
#import PySimpleGUI as sg
sg.ChangeLookAndFeel('DarkBlue17')
form = sg.FlexForm('Lucky RandomNumbers', default_element_size=(40, 1))
column1 = [[sg.Text('Column 1', background_color='#d3dfda', justification='center', size=(10,1))],
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]
layout = [
[sg.Text('Lucky Number Generator', size=(30, 1), font=("Helvetica", 25))],
[sg.Text('Enter low value'), sg.InputText('',size=(5, 3),key='low_end'), sg.Text('Enter high value'), sg.InputText('',size=(5, 3), key='high_end')],
[sg.Submit(), sg.Cancel()]
]
event, values = form.Layout(layout).Read()
randomlist = random.sample(range('low_end'), ('high_end'), 5)
sg.Popup(randomlist, ' ')
When I run it I get:
TypeError: 'str' object cannot be interpreted as an integer
I have tried several solutions but nothing seems to work.
Upvotes: 1
Views: 721
Reputation: 88
Try this.
randomlist = random.sample(range(int(values['low_end']), int(values['high_end'])), 5)
You can only get the value if you get it from the values dictionary.
Upvotes: 1