3

I am trying to run a simple python script (3.6.8), using tkinter on my Ubuntu (18.04) Windows Subsystem.

import tkinter
root = tkinter.Tk()
root.mainloop()

I always get the following error: _tkinter.TclError: no display name and no $DISPLAY environment variable

I tried to fix it myself with different hints from google, but the only thing I achieved is that I got a new error code after running those two commands:

export DISPLAY=0.0

xhost +

New error code: _tkinter.TclError: couldn't connect to display "0.0"

How can i run tkinter on Ubuntu?

Thank you very much in advance for your help!

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
darre
  • 31
  • 1
  • 3
  • How are you importing tkinter? With underscore prefix? With upper lower chars? I think you need a canvas to display, see https://stackoverflow.com/a/57830452/495455 you should provide your code – Jeremy Thompson Dec 15 '19 at 22:23
  • with lower chars. I added a snipped of example code (the original code is to long but works finde if I execute it in my Windows command prompt). even this simple bit generates the error: no display etc. when trying to run it in ubuntu – darre Dec 15 '19 at 22:33
  • I don't think WSL supports GUI programs. – jasonharper Dec 15 '19 at 22:37
  • 4
    Unfortunately I was able to solve the problem: @jasonharper: You're right WSL does not support GUI programs but I found a work around by using a X-Server. I followed the instructions in the following link: https://virtualizationreview.com/articles/2018/01/30/hands-on-with-wsl-graphical-apps.aspx My python script now displays the GUI even when executed via Ubuntu. Anyway, thanks for your fast replies! – darre Dec 15 '19 at 22:51
  • Does this answer your question? [\_tkinter.TclError: no display name and no $DISPLAY environment variable](https://stackoverflow.com/questions/37604289/tkinter-tclerror-no-display-name-and-no-display-environment-variable) – Karl Knechtel Apr 28 '23 at 20:52

0 Answers0