hoffstadt / hoffstadt/DearPyGui
OS filedialog using Tkinter
- Dominant language
- C++
- Stars
- 15.6k
- Forks
- 783
- PR merge metrics
- No merged PRs in 30d
Description
## 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` and `third_example.py` and `get_file.py`
running `python3 first_example.py` gives `zsh: trace trap python3 first_example.py`
running `python3 example_1141.py` gives `zsh: segmentation fault python3 example_1141.py`
running `python3 subprocess_demo.py` works fine
## Expected 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:
```python
# first_example.py
import dearpygui.dearpygui as dpg
from tkinter import filedialog
dpg.create_context()
def open_file():
file = filedialog.askopenfilename() # Gives trace trap
print(f"{file=}")
with dpg.window(tag="Demo"):
dpg.add_button(label="Open file", callback=open_file)
dpg.create_viewport(title="Demo", width=600, height=412)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("Demo", True)
dpg.start_dearpygui()
dpg.destroy_context()
```
---
Example from #1141, updated to last dpg version, unworkable, gives segfault:
```python
# example_1141.py
from dearpygui.dearpygui import *
from tkinter import Tk
from tkinter import filedialog
import os
def new():
Tk().withdraw() # Gives segmentation fault
file_path = filedialog.askdirectory(initialdir=os.getcwd())
print(file_path)
DirString = "Chosen Directory: "+file_path
set_value(dirpath,DirString)
with window(label="Tutorial") as main_window:
add_button(label="Choose Directory",callback=new)
dirpath = add_text(default_value="Chosen Directory: None Selected")
set_primary_window(main_window, True)
start_dearpygui()
```
---
Third, fine working (but weird looking) example:
```python
# get_file.py
from tkinter import filedialog
file = filedialog.askopenfilename()
print(file, end="")
```
```python
# third_example.py
import dearpygui.dearpygui as dpg
from tkinter import filedialog
from sys import executable # To run subprocess
from subprocess import check_output
dpg.create_context()
def open_file():
file = check_output([executable, "get_file.py"]) # Works fine, but looks weird
print(f"{file=}")
with dpg.window(tag="Demo"):
dpg.add_button(label="Open file", callback=open_file)
dpg.create_viewport(title="Demo", width=600, height=412)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("Demo", True)
dpg.start_dearpygui()
dpg.destroy_context()
```
Contributor guide
Assessment
This issue has not been assessed yet.