3 outputs to 1 trouble with pysimplegui and python script

I have a script with 3 different random number lists.
Depending of witch of the 3 buttons I press , result is printed in shell . (Working)
I then want the result to show in another sg.window.
Now I have the results in 3 different sg.windows .

How can I get the result in just one window?
Any tips for a beginner?

script:

#code

  import os
2    import random
3    import PySimpleGUI as sg
4    
5    os.chdir("C:/windows/system32/")
6    
7    current_dir = r"C:/windows/system32/"
8    
9    randomlist1 = []
10   randomlist2 = []
11   randomlist3 = []
12   sg.theme('Purple')  # Add a touch of color
13   
14   layout = [[sg.Text('WIN$$$$$')],
15             [sg.Button('V86', button_color=('white', 'blue'), key='V86'),
16              sg.Button('LOTTO', button_color=('white', 'green'), key='LOTTO'),
17              sg.Button('V75', button_color=('blue', 'yellow'), key='V75'),
18              sg.Button('4 quit', button_color=('red', 'black'), key='4 quit')]]
19   
20   window = sg.Window('Var god välj spelform!', layout, )
21   
22   while True:
23       event, values = window.read()
24   
25       if event == sg.WIN_CLOSED:
26           break
27       elif event == 'V86':
28           randomlist1 = random.sample(range(1, 18), 8)
29           print(randomlist1, ('V86'))
30   
31   
32       elif event == 'LOTTO':
33           randomlist2 = random.sample(range(1, 35), 7)
34           print(randomlist2, ('LOTTO'))
35   
36   
37       elif event == 'V75':
38           randomlist3 = random.sample(range(1, 18), 7)
39           print(randomlist3, ('V75'))
40   
41       elif event == '4 quit':
42           break
43   
44       window.close()
45   
46   layout = [[sg.Text('V 8 6')],
47             [sg.InputText(randomlist1, )],
48             [sg.Cancel()]]
49   
50   window = sg.Window('$$$$$$', layout)
51   
52   event, values = window.read()
53   window.close()
54   
55   layout = [[sg.Text('LOTTO')],
56             [sg.InputText(randomlist2)],
57             [sg.Cancel()]]
58   
59   window = sg.Window('€€€€€€', layout)
60   
61   event, values = window.read()
62   
63   window.close()
64   
65   layout = [[sg.Text('V 7 5')],
66             [sg.InputText(randomlist3)],
67             [sg.Cancel()]]
68   
69   window = sg.Window('£££££', layout)
70   
71   event, values = window.read()
72   
73   window.close()
74   
````end

I would make your main window as you already have, and a single other
window for the result. Then just update the display in the second
window. Your code seems to make and close windows, and never have more
than one at a time (they’re all referenced by the same variable
“window”, and you close each window).

Maybe something like this:

layout = [[sg.Text('WIN$$$$$')],
          [sg.Button('V86', button_color=('white', 'blue'), key='V86'),
           sg.Button('LOTTO', button_color=('white', 'green'), key='LOTTO'),
           sg.Button('V75', button_color=('blue', 'yellow'), key='V75'),
           sg.Button('4 quit', button_color=('red', 'black'), key='4 quit')]]
main_window = sg.Window('Var god välj spelform!', layout, )

layout = [[sg.Text("Result"),
           sg.Text("Result Here")]]
result_window = sg.Window("results!", layout)

then in your if/elif/… for the buttons also update the result_window
text widget when you print.

I also wonder if the code you’ve supplied is exactly what you’re
running, because:

while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == ‘V86’:

window.close()

The window.close() is inside the loop, meaning the window disappears
after the first button click.

Cheers,
Cameron Simpson cs@cskk.id.au

Hi Cameron! And thanks for helping out. :blush:
It nearly got me where I wanted.
I still can´t figure out; If I press button for V86 -->triggers randomlist1 (8 numbers)
prints in shell. But how do I get these numbers in the "result_window?
Result_window open , but is empty.
Hope you understand what I mean.?

EDIT , SOLVED
I used sg.popup , and that works! :smiley: