Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tkinter problem

1,907 views
Skip to first unread message

Liya Ann Sunny

unread,
Jun 18, 2021, 2:28:35 AM6/18/21
to
I am using Colab. How could solve this problem.
import tkinter as Tk
from tkinter import *
import sys
import os
#create main window
master = Tk()
master.title("tester")
master.geometry("300x100")


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

# Run forever!
master.mainloop()
The error shows that :
<ipython-input-17-a60049376d65> in <module>()
9
10 #create main window
---> 11 master = Tk()
12 master.title("tester")
13 master.geometry("300x100")

/usr/lib/python3.7/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"

Christian Gollwitzer

unread,
Jun 18, 2021, 2:44:40 AM6/18/21
to
Am 18.06.21 um 08:28 schrieb Liya Ann Sunny:
> I am using Colab. How could solve this problem.
> TclError: couldn't connect to display ":0.0"

You're either not running an X server, or having problems to connect to it.

Are you sure that Google Colab supports X11 at all? This link doesn't
seem to support that idea:

https://stackoverflow.com/questions/61168210/is-there-any-way-to-use-tkinter-with-google-colaboratory

Christian


Jach Feng

unread,
Jun 18, 2021, 11:59:56 PM6/18/21
to
liyaanns...@gmail.com 在 2021年6月18日 星期五下午2:28:35 [UTC+8] 的信中寫道:
>>> import tkinter as Tk
>>> Tk
<module 'tkinter' from 'C:\\Users\\jfong\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\tkinter\\__init__.py'>
>>> from tkinter import *
>>> Tk
<class 'tkinter.Tk'>
>>> tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'tkinter' is not defined
>>>

--Jach

Christian Gollwitzer

unread,
Jun 19, 2021, 12:27:54 AM6/19/21
to
Am 19.06.21 um 05:59 schrieb Jach Feng:
>>>> import tkinter as Tk
>>>> Tk
> <module 'tkinter' from 'C:\\Users\\jfong\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\tkinter\\__init__.py'>
>>>> from tkinter import *
>>>> Tk
> <class 'tkinter.Tk'>
>>>> tkinter
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'tkinter' is not defined
>>>>

What's the point? That has no relation to the question.

"import A as B" does not define A. That's a feature, not a bug.

Christian

Jach Feng

unread,
Jun 19, 2021, 1:16:33 AM6/19/21
to
Christian Gollwitzer 在 2021年6月19日 星期六下午12:27:54 [UTC+8] 的信中寫道:
No, it's not. It's only because this line triggers my response:-)
> label1 = tkinter.Label(master, text='Hellooooo')

--Jach

Christian Gollwitzer

unread,
Jun 19, 2021, 1:54:46 AM6/19/21
to
Am 19.06.21 um 07:16 schrieb Jach Feng:
You have posted this as an answer to Liya's question about Google Colab.
What you wrote has nothing to do with it and does not help with Liya's
problem.

I guess you wanted to post another question? Then please open a new
thread. In addition, the question is unclear, you just posted a
transcript of three lines of Python.

Christian

Jach Feng

unread,
Jun 19, 2021, 2:49:03 AM6/19/21
to
Christian Gollwitzer 在 2021年6月19日 星期六下午1:54:46 [UTC+8] 的信中寫道:
I posted to point out there is an error in Liya's script. It's not related to Colab, but it may relate to his problem.

--Jach

Terry Reedy

unread,
Jun 19, 2021, 2:51:38 PM6/19/21
to
On 6/18/2021 2:28 AM, Liya Ann Sunny wrote:
> I am using Colab. How could solve this problem.
> import tkinter as Tk

If you do this, import 'as tk'.

> from tkinter import *

The second import overwrites the first since it imports tkinter.Tk as
'Tk'. Don't try to do both.
--
Terry Jan Reedy

Christian Gollwitzer

unread,
Jun 20, 2021, 7:18:37 AM6/20/21
to
Am 19.06.21 um 08:48 schrieb Jach Feng:
> Christian Gollwitzer 在 2021年6月19日 星期六下午1:54:46 [UTC+8] 的信中寫道:
>> I guess you wanted to post another question? Then please open a new
>> thread. In addition, the question is unclear, you just posted a
>> transcript of three lines of Python.

> I posted to point out there is an error in Liya's script. It's not related to Colab, but it may relate to his problem.
>

Ah! Now I get it, sorry, missed that earlier.

Christian
0 new messages