1

I am running the following code on Google Colab to create a GUI for a chatbot which I have created, but it is giving an error. I have tried other SO Answers regarding this but the solutions did not help. I am working with tkinter for the first time so I am unable to understand how to proceed. How to fix this?

CODE

#Creating GUI with tkinter
import tkinter
from tkinter import *


def send():
    msg = EntryBox.get("1.0",'end-1c').strip()
    EntryBox.delete("0.0",END)

    if msg != '':
        ChatLog.config(state=NORMAL)
        ChatLog.insert(END, "You: " + msg + '\n\n')
        ChatLog.config(foreground="#442265", font=("Verdana", 12 ))

        res = chatbot_response(msg)
        ChatLog.insert(END, "Bot: " + res + '\n\n')

        ChatLog.config(state=DISABLED)
        ChatLog.yview(END)

base = Tk()
base.title("Hello")
base.geometry("400x500")
base.resizable(width=FALSE, height=FALSE)

#Create Chat window
ChatLog = Text(base, bd=0, bg="white", height="8", width="50", font="Arial",)

ChatLog.config(state=DISABLED)

#Bind scrollbar to Chat window
scrollbar = Scrollbar(base, command=ChatLog.yview, cursor="heart")
ChatLog['yscrollcommand'] = scrollbar.set

#Create Button to send message
SendButton = Button(base, font=("Verdana",12,'bold'), text="Send", width="12", height=5,
                    bd=0, bg="#32de97", activebackground="#3c9d9b",fg='#ffffff',
                    command= send )

#Create the box to enter message
EntryBox = Text(base, bd=0, bg="white",width="29", height="5", font="Arial")
#EntryBox.bind("<Return>", send)


#Place all components on the screen
scrollbar.place(x=376,y=6, height=386)
ChatLog.place(x=6,y=6, height=386, width=370)
EntryBox.place(x=128, y=401, height=90, width=265)
SendButton.place(x=6, y=401, height=90)

base.mainloop()

ERROR

TclError                                  Traceback (most recent call last)
<ipython-input-35-896b278da15a> in <module>()
     19         ChatLog.yview(END)
     20 
---> 21 base = Tk()
     22 base.title("Hello")
     23 base.geometry("400x500")

/usr/lib/python3.6/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: couldn't connect to display ":0.0" 
Ishan Dutta
  • 897
  • 4
  • 16
  • 36
  • Does this answer your question? [docker \_tkinter.TclError: couldn't connect to display](https://stackoverflow.com/questions/49169055/docker-tkinter-tclerror-couldnt-connect-to-display) – Olvin Roght Oct 22 '20 at 19:54
  • No, I had already tried it. It works for docker, but I am using this on Google Colab. – Ishan Dutta Oct 22 '20 at 19:57
  • tkinter requires a display. I don't think google colab provides a display. – Bryan Oakley Oct 22 '20 at 21:32

0 Answers0