DearPyGui
DearPyGui copied to clipboard
destroy_context doesn't clean up the window
Version of Dear PyGui
Version: 1.9.1 Operating System: Ubuntu 22.04 (KDE Plasma 5.27.7)
My Issue
Calling dpg.destroy_context()
doesn't close the window, but just makes it unresponsive.
This seems like a very basic thing, so maybe there's something wrong with my OS or window manager? It works as expected on my Windows 11 system.
I also tried a range of DPG versions, all of them have the same issue on my Linux system.
To Reproduce
Run the code below and simply close the window by clicking on the x. The window doesn't close but just becomes unresponsive. It does unblock dpg.start_dearpygui()
, calls destroy_context
and goes into the while True loop as expected.
Expected behavior
The window should close properly.
Standalone, minimal, complete and verifiable example
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
with dpg.window(label="tutorial"):
dpg.add_text("Hello world")
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
print("window closed")
while True:
pass
Probably Linux-only (with the minimal example given), because on Windows you can only get to print("window closed")
by closing the window :rofl:
Here's a modified example that will show somewhat similar behavior on Windows:
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
with dpg.window(label="tutorial"):
dpg.add_text("Hello world")
dpg.add_button(label="Exit", callback=lambda: dpg.stop_dearpygui())
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
print("window closed")
while True:
pass
Instead of closing the window, press Exit - and you'll get an unresponsive window.
Also, this is most probably a duplicate of #2013 - see my comment in that issue.
Also, there's a discussion in #1593 which shows how old the issue is! :joy:
Ah, sorry for the duplicate, moving to #2013.
I'd like to point out that both #2013 and #1593 are closed - but not fixed. Let's leave at least one issue open ;)
Alright, since I can't reopen the other issues I'll stay here :D
Any plans on addressing this issue? If you are sure that mvCleanupViewport
provides the intended functionality I could look into adding it to destroy_context()
, if you think that makes sense.
I'm not sure how to fix this issue properly - it's up to @hoffstadt to decide... It might well be that mvCleanupViewport
needs some rework. Unfortunately I don't have spare time at the moment to play with mvCleanupViewport
. Maybe later.
Having the same issue on POPOS with SwayWM. I have to kill the python process to close the viewport. Is there a way around this? For now this is a showstopper for me to use dpg!
On Windows, you could use WinAPI wrappers to close your window directly. I don't know if such a package exists on Linux - basically you need some kind of a SwayWM or Wayland API. Google says there's PyWayland, at least.
This would make your code platform-dependent, but with this kind of issues there's no cross-platform workarounds.
Other GUI frameworks I tried don't have this problem and am unsure if this is wayland related, more seems like a bug or oversight.
It's a bug in DPG, just like I said in a comment in another ticket.
I'm talking about Wayland because you can use its API to forcefully close the window - as a workaround for the DPG bug. DPG does not close the window itself. Most users don't see it because their programs end immediately after dpg.destroy_context()
.
As an option, use dpg.minimize_viewport
before destroy_context
to get the unresponsive window out of view. Only if your program ends in a reasonably short time after that (so that the user doesn't try to restore the minimized window).
Any update on this?
PR #2275 is going to fix this.