I am trying to run this code on Ubuntu 20.04 LTS using the Anaconda latest distribution of Python (3.8.3)
from tkinter import *
root = Tk() # THIS IS THE LINE CAUSING THE ERROR
label = Label(root, text='Hello World!')
label.pack()
root.mainloop()
When I run this, I get the following error:
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
However, when I run the same lines on the bash terminal on the python shell, everything works perfectly and the window opens with the label without any issues. I am using Visual Studio Code and the Anaconda distribution of python. I would really appreciate it if you could let me know what I am doing wrong. Thanks so much, cheers!