-
-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OS filedialog using Tkinter #2338
Comments
Disclaimer: I don't have any experience with Tkinter, and what's worse, I don't have tkinter itself (on Windows, it's optional), so can't really test your code. Nevertheless, here are some thoughts on the topic. I believe that to successfully use Tkinter with DPG, one needs to understand events (and the event loop) and threads in both libraries. Here's a piece of doc describing threads in Tkinter: https://docs.python.org/3/library/tkinter.html#threading-model In DPG, you have two threads: the main thread runs the rendering loop, and a secondary thread (created by DPG internally) runs callbacks and handlers. When you click a button, its callback is run on that secondary "handlers thread". Now, what happens in your 1st and 2nd example is Tk is run on that secondary thread, and somehow it doesn't like that. In 3rd example, you're running it in a separate process, and therefore in the main thread (whereas DPG's rendering loop runs in the main thread of another process). Somehow Tkinter doc suggests that it can be used from any thread, but googling it up shows a number of discussions saying that it should be run on the main thread (albeit most of them dating back at 2010-2012). So it's probably a matter of properly initializing Tkinter and using it in the right context. Unfortunately, like I said, I can't play with it and therefore can't provide any ready-to-use solutions. |
Got the same problem and I think I figured out the solution albeit not being very clean either.
Alternative, the original code works perfectly on Windows for those who are interested.
and if you can afford another external library, xdialog works pretty well on my system
|
Version of Dear PyGui
Version: 1.11.1 (on python 3.12.2, dpg installed via pip)
Operating System: macOS Sonoma 14.5
My Issue/Question
I wanted to create a system file dialog (instead of the file dialog provided by dpg.file_dialog), using Tkinter. When creating the dialog, various very strange errors occurred, which are impossible to handle and understand the reason for their occurrence. Over time I have found a working solution, but I don't think it's obvious or correct.
I also saw a similar problem in #1141, but by rewriting the solution I got a different error
To Reproduce
copy the code from the examples into the files
first_example.py
,example_1141.py
andthird_example.py
andget_file.py
running
python3 first_example.py
giveszsh: trace trap python3 first_example.py
running
python3 example_1141.py
giveszsh: segmentation fault python3 example_1141.py
running
python3 subprocess_demo.py
works fineExpected behavior
Filedialog, working in one file without need to call subprocess.
Screenshots/Video
Fine working example with subprocess:
Standalone, minimal, complete and verifiable example
The first obvious but unworkable example:
Example from #1141, updated to last dpg version, unworkable, gives segfault:
Third, fine working (but weird looking) example:
The text was updated successfully, but these errors were encountered: