I tried to use tkinter on Google Colab. And I got the error:
TclError: no display name and no $DISPLAY environment variable
And I tried this method in this answer: Is there any way to use Tkinter with Google Colaboratory?
But still I got an error:
TclError: couldn't connect to display ":1.0"
Here is my code:
import random
import os
from tkinter import *
import numpy as np
!apt-get install -y xvfb # Install X Virtual Frame Buffer
os.system('Xvfb :1 -screen 0 1600x1200x16 &')
os.environ['DISPLAY']=':1.0'
You guys didn't understand what is going on here... I read the answers from How to use GUI in Google Colab? and Is there any way to use Tkinter with Google Colaboratory? and I think they are not answering my question.
Somebody asked if it is possible to use Tkinter in Google Colab in this question: Is there any way to use Tkinter with Google Colaboratory?, and the first answer asserted that adding these lines of code into the very beginning would be helpful.
!apt-get install -y xvfb
os.system('Xvfb :1 -screen 0 1600x1200x16 &')
os.environ['DISPLAY']=':1.0'
It says this will create a virtual display so that we can use Tkinter in Google Colab. I tried this and it failed. So now I am asking why it failed.
I know some answers stated that you cannot use a GUI on Google Colab. BUT there are answers saying that it is possible to create a virtual display. However after doing what they said, I still got the error I posted. So I am wondering is it really impossible to use tkinter in Colab or it is that whatever code from other answers that I used has something wrong with them and that can be fixed.
Please consider reopening this question as I think this is not a duplicated question.