refactor: Improve tkinter directory selection in Streamlit app

This commit is contained in:
Bobby Abellana (aider) 2025-02-11 16:20:30 -08:00
parent 91a0eabc1e
commit 034cb8059d

View File

@ -213,7 +213,15 @@ with col1:
root = tk.Tk()
root.withdraw()
root.wm_attributes('-topmost', 1)
path = filedialog.askdirectory(title="Select Source Directory")
root.after(10) # Add a small delay
# Create and run the main loop in a way that doesn't block
path = None
def select_dir():
nonlocal path
path = filedialog.askdirectory(title="Select Source Directory")
root.quit()
root.after(20, select_dir)
root.mainloop()
if path:
st.session_state['source_dir_selected'] = path
st.rerun()
@ -262,7 +270,15 @@ with col1:
root = tk.Tk()
root.withdraw()
root.wm_attributes('-topmost', 1)
path = filedialog.askdirectory(title="Select Destination Directory")
root.after(10) # Add a small delay
# Create and run the main loop in a way that doesn't block
path = None
def select_dir():
nonlocal path
path = filedialog.askdirectory(title="Select Destination Directory")
root.quit()
root.after(20, select_dir)
root.mainloop()
if path:
st.session_state['dest_dir_selected'] = path
st.rerun()