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
#5
(Jan-09-2021, 10:27 PM)Serafim Wrote: As you use windows and not popups you have to catch signals from all windows.
Your code works with minor changes (I changed the "rc= reverseComplement(seq)" as I don't know what it does)

import PySimpleGUI as sg
 
sg.theme('DarkAmber')
 
layout = [[sg.Text('Reverse complement:', size=(15,1), key='-OUTPUT-')],
          [sg.Input(key='-IN-')],
          [sg.Button('Convert'), sg.Button('Exit'), sg.Button('Help')]]
 
window= sg.Window('Reverse Complement Converter', layout, finalize = True)
 
window_help = None
 
 
while True:
    win, event, values = sg.read_all_windows() # Read all signals from all windows
    if event in (sg.WIN_CLOSED, 'Exit', 'Cancel'):
        if win == window:
            break
        elif window_help and win == window_help:
            window_help.close()
            window_help = None
    elif event == 'Convert':
        seq=values['-IN-']
        rc= "YES!" #reverseComplement(seq)
        window['-OUTPUT-'].update(rc)   
    elif event == "Help":
        layout_help = [[sg.Text("This program requires a DNA sequence as an input and returns the reverse complement")],[sg.Button("Cancel")]]
        window_help = sg.Window("Help", layout_help, finalize = True)
         
window.close()

Thanks for your reply Serafim. Indeed, with your changes I can open and close the help window. Thank you! FYI: reverseComplement is a custom function which processes a string and outputs a string.

I have a few questions though:

1) In line 19 of your code, why did you write
elif window_help and win == window_help:
and not just
elif win == window_help
? I removed the "window_help" in this statement, and the GUI appears to work fine.

2)In the same elif statement as question 1. Why did you add
window_help=None
(line 21). Again, if I delete this line, it seems to work fine.

3)When I click the "Convert" button, the string processed by the reverseComplement function (i.e. "rc" value), should appear to the right of "Reverse complement:" as it is the "key" of this Text. This happend in my initial script. However, when I now press "Convert", the "rc" value replaces the "Reverse complement:" string. Any idea why this happens and how I could fix this? When I look at the code, I fail to understand why it replaces the whole string.

Thanks!
Reply


Messages In This Thread
RE: closing a "nested" window with a button in PySimpleGUI and repeating this process - by Robby_PY - Jan-10-2021, 11:22 AM

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