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
#6
In a GUI there are a lot of signals telling the application what is going on and some of these signals are a bit confusing, e.g. "sg.WIN_CLOSED" which only tells you that a window has given "None" as signal, not telling which window. Thus, I note that to start with there is no help window by declaring
window_help=None
and that means that
if window_help and win == window_help
ensures that the part
win == window_help
is tested only if window_help has a value (is referring to a window). If not you may have a crash when trying to close the window_help window (error: 'NoneType' object has no attribute 'close'). The python construct "if A and B" calculates B only if A is True (sort of a shortcut of the whole expression).

It might be that I am overly careful, but in my experience (50+ years of programming in a multitude of languages and in a large range of applications, the biggest counting millions of lines of code. I am 75 and still active as a programmer), if you are not careful with these matters, sooner or later there is a crash.
And, when that occurs, you want to be able to find the bug quickly. The more careful you are, the more precautions you take, the simpler to locate the error.

So far your application is small but it will grow. Being careful is a good basis for application development.
Robby_PY likes this post
Reply


Messages In This Thread
RE: closing a "nested" window with a button in PySimpleGUI and repeating this process - by Serafim - Jan-10-2021, 05:31 PM

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