0

I have been programming remotely lately by using GitHub codespaces. I have been using the dev container for Python 3 to compile and run my code and it's been working just fine so far.

I currently have a program that is using the Tkinter module. I am pretty sure it has been installed correctly, but I am getting an error message whenever I am running it. I have no idea if it is even possible to run this sort of thing on a GitHub workspace.

The code I have been using is very basic Tkinter code.

Code:

import tkinter

#create main window
master = tkinter.Tk()
master.title("tester")
master.geometry("300x100")


#make a label for the window
label1 = tkinter.Label(master, text="Hello")
# Lay out label
label1.pack()

# Run forever!
master.mainloop()

Whenever I try running this code on a GitHub codespace with my dev container I end up getting this error message:

*Traceback (most recent call last):
  File "/workspaces/compile-python/cheese.py", line 4, in <module>
    master = tkinter.Tk()
             ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/tkinter/__init__.py", line 2345, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: no display name and no $DISPLAY environment variable*

I understand that it might not even be possible in general and that it might not be because of the way I wrote the code.

6
  • 1
    Why would you expect this to work at all? A GUI appears on the local display of the computer it's running on - which does you no good at all when it's running on a remote server (not that a server normally even has a local display). Commented Feb 26, 2024 at 2:30
  • Well, somewhere in GitHub documentation or whatever, it said something about when running something like this the output to your code will be shown in like another tab or something after a little notification pops up in the bottom left corner. Of course, I could be wrong and have interpreted this incorrectly. Commented Feb 26, 2024 at 2:42
  • 1
    Textual output of your code can easily be redirected somewhere else. Commented Feb 26, 2024 at 2:51
  • I assume that this is the only type of output that can be displayed." Commented Feb 26, 2024 at 2:53
  • Have a look at github.com/devcontainers/features/tree/main/src/desktop-lite. Commented Feb 26, 2024 at 2:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.