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
#1
Question 
Hello,

I'm currently experimenting with my first GUI in Python (or in any other programming language) using PySimpleGUI and I'm stumbling on some issues I cannot resolve.

This is the code I've written so far:

Import PySimpleGUI as sg

sg.theme('DarkAmber')

layout = [[sg.Text('Reverse complement:'), sg.Text(size=(15,1), key='-OUTPUT-')],
          [sg.Input(key='-IN-')],
          [sg.Button('Convert'), sg.Button('Exit'), sg.Button('Help')]]

layout_help = [[sg.Text("This program requires a DNA sequence as an input and returns the reverse complement")],[sg.Button("Cancel")]]

window = sg.Window('Reverse Complement Converter', layout)

window_help = sg.Window("Help", layout_help)

while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    
    if event == 'Convert':
        seq=values['-IN-']
        rc= reverseComplement(seq)
        window['-OUTPUT-'].update(rc)
        
    if event == "Help":
        window_help.read()
        if event == "Cancel" or event == sg.WIN_CLOSED:
            window_help.close()
        
window.close()
If I run the script, the appropriate window opens:
[Image: ezgif-3-60b97a2c9c92.jpg]

The "Convert" button, linked to my custom reverseComplement() function actually functions. So the general functionality of my GUI works.

However, I experience following issues:
1) when I press the button "Help", I get the correct new windows pops up. However, I cannot close this help window by pressing the "Cancel" button. Pressing Cancel, does not do anything at the moment. I can, however, close it by pressing "X" in the top right corner. Why is this? Both the Cancel and X buttons should close the window right?

I also tried the following code without succes:

if event == "Help":
        window_help.read()
        if event == "Cancel" or event == sg.WIN_CLOSED:
            break
2) Also regarding the "Help" window: When I press "Help" and thereafter close the help window by pressing "X", nothing happens when I press te "Help" button again. Why is this? If the program stays in the event loop, it should be able to process "Help" more than once?



Any help would be much appreciated.
Reply


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

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

Forum Jump:

User Panel Messages

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