Is there any way to use Tkinter with Google Colaboratory?

As Run gym-gazebo on Google Colaboratory says, you need to run a framebuffer server (that will emulate a graphical screen) and create a DISPLAY envvar pointing to it.

!apt-get install -y xvfb # Install X Virtual Frame Buffer
import os
os.system('Xvfb :1 -screen 0 1600x1200x16  &')    # create virtual display with size 1600x1200 and 16 bit color. Color can be changed to 24 or 8
os.environ['DISPLAY']=':1.0'    # tell X clients to use our virtual DISPLAY :1.0

However, if you want to interact with the GUI, that’s going to be hard, because Colab doesn’t support interactive screens out of the box.

Leave a Comment