0

I tried to use Tkinter on Python server version. (Linux) but I failed. How can I use tkinter on Python server version ?

-----------------------------------------------------------------------------
import tkinter ; window = tkinter.Tk()
-----------------------------------------------------------------------------

TclError                                  Traceback (most recent call last)
<ipython-input-16-c9e945514158> in <module>
      1 import tkinter
----> 2 window = tkinter.Tk()

~/anaconda3/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
   2021                 baseName = baseName + ext
   2022         interactive = 0
-> 2023         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   2024         if useTk:
   2025             self._loadtk()

TclError: no display name and no $DISPLAY environment variable
Novel
  • 13,406
  • 2
  • 25
  • 41
BG KIM
  • 9
  • 2
  • Does this answer your question? [Ubuntu: \_tkinter.TclError: no display name and no $DISPLAY environment variable](https://stackoverflow.com/questions/62718967/ubuntu-tkinter-tclerror-no-display-name-and-no-display-environment-variable) – Lies Jan 04 '21 at 02:17
  • Do your server have a graphical desktop environment running? – acw1668 Jan 04 '21 at 02:42

1 Answers1

0

Set the DISPLAY environment variable to :0.0 Generally you would do that with this command in the terminal:

export DISPLAY=:0.0

or this in python:

import os
os.environ["DISPLAY"] = ":0.0"
Novel
  • 13,406
  • 2
  • 25
  • 41
  • You should add that this requires that the server be running X11, and that the tkinter windows will be displayed on the server's display. – Bryan Oakley Jan 04 '21 at 03:22