Python Forum
closing a "nested" window with a button in PySimpleGUI and repeating this process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
closing a "nested" window with a button in PySimpleGUI and repeating this process
#3
(Dec-07-2020, 09:35 PM)deanhystad Wrote: I don't see how this could work.
if event == "Help":
        window_help.read()
        if event == "Cancel" or event == sg.WIN_CLOSED:
            break
To get to the "break" event has to equal "Help" and at the same time equal "Cancel" or sg.WIN_CLOSED. In you while loop you read one event at a time and process one event at a time.

You should also use elif to limit the code executed for each loop.
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
     
    if event == 'Convert':  # Don't need elif here because of break
        seq=values['-IN-']
        rc= reverseComplement(seq)
        window['-OUTPUT-'].update(rc)
         
    elif event == "Help":
        window_help.read()

    elif event == "Cancel" or event == sg.WIN_CLOSED:
        window_help.close()

Thank you for your reply. I added the second if statement (below) with the reasoning that it would only apply to the "Help" window. So if "Help" is pressed, then a new window pop ups, with its own new event and if statement. That's how I used nested if statements before, so I thought it also worked like that in an event loop?

if event == "Help":
        window_help.read()
        if event == "Cancel" or event == sg.WIN_CLOSED:
            break
Thanks for rewriting the code. However, I still cannot close the Help window using the "Cancel" button. Also it is not possible to press Help twice. Any ideas how to solve this?
Reply


Messages In This Thread
RE: closing a "nested" window with a button in PySimpleGUI and repeating this process - by Robby_PY - Dec-08-2020, 07:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 615 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] PyQt5 window closing when trying to display a graph bianca 4 1,785 Aug-12-2023, 03:25 PM
Last Post: bianca
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 820 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,143 May-25-2023, 07:37 PM
Last Post: deanhystad
  PysimpleGUI window update dynamically SamLiu 6 4,114 Apr-05-2023, 02:32 PM
Last Post: SamLiu
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,278 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  PySimpleGUI Try Except jamesaarr 1 1,977 Nov-18-2021, 02:02 PM
Last Post: jamesaarr
  .get() invoke after a button nested press iddon5 5 3,328 Mar-29-2021, 03:55 AM
Last Post: deanhystad
  [PyQt] Received RunTimeError after script concludes, closing Dialog Window (clicking x-out) skipper0802 0 2,591 Oct-09-2020, 09:23 PM
Last Post: skipper0802
  how to add elements in the other window? (pysimplegui) syafiq14 0 2,357 Jul-20-2020, 10:35 PM
Last Post: syafiq14

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020