_tkinter.TclError: couldn't connect to display ":0"

Hello friends,
I face this problem and I don’t know what to do… are there any solutions?

2021-05-11 23:16:39.942 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/script_runner.py", line 337, in _run_script
    exec(code, module.__dict__)
  File "/app/thefinale/main.py", line 305, in <module>
    main()
  File "/app/thefinale/main.py", line 200, in main
    Fichier_final(file)
  File "/app/thefinale/main.py", line 37, in Fichier_final
    root = tk.Tk()
  File "/usr/local/lib/python3.9/tkinter/__init__.py", line 2270, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"

Hi @SAMI_EL_KHARBAOUI, welcome to the Streamlit community!

Hard to say without seeing the code, but I suspect using Tkinter on Streamlit sharing won’t work, because it’s a “headless” server. Meaning, there’s no window for the container on Streamlit sharing to open (because there’s no video card, no “display” attached).

Since Streamlit is a UI/app toolkit, and tkinter is a similar GUI for the desktop, what are you trying to have happen with this app?

Best,
Randy

1 Like

Thank you @randyzwitch for replying!
you can check my code here GitHub - sami-elk/thefinale
I’m trying to generate a windows to choose the path where I want to download my csv file after the process. there is my app if you want to see more https://share.streamlit.io/sami-elk/thefinale/main/main.py
thank you again

Unfortunately, that will not work on a remote computer for the reasons I mentioned (the container being a “headless” server). For that to work, you’d have to have permissions to save to the server running the Streamlit app; this works during development, because your code is running in the same place where you are trying to save.

I don’t have a workaround for this, but maybe someone else in the community will.

Best,
Randy

1 Like