【问题标题】:Error in GoogleColab (Python)- TclError: no display name and no $DISPLAY environment variable [duplicate]GoogleColab(Python)中的错误 - TclError:没有显示名称和 $DISPLAY 环境变量 [重复]
【发布时间】:2021-07-18 22:04:30
【问题描述】:

有人知道如何在 GoogleColab Notebook 中修复 Python 中的以下错误吗?我正在运行以下代码:-

import matplotlib.pyplot as plt

from matplotlib import style
style.use('fivethirtyeight')

import tkinter as tk
from tkinter import filedialog
from tkinter import *
from PIL import ImageTk, Image

import numpy
import keras 
from keras.models import load_model

from sklearn.metrics import accuracy_score

model = load_model('training_model.h5')

classes = { 1: 'Speed Limit 20 km/h',
            2: 'Speed Limit 30 km/h',
            3: 'Speed Limit 50 km/h' }

#initialize GUI

top = tk.Tk()
top.geometry('800x600')
top.title('Traffic Sign Recognition Project Report')
top.configure(background='#EEE')

label=Label(top,background='#CDCDCD', font=('arial',15,'bold'))

sign_image = Label(top)

我在-> top = tk.Tk()一行得到错误

【问题讨论】:

  • 这里有很多相同的问题,你检查了吗?
  • 是的,但没有人为我工作。

标签: python tkinter google-colaboratory


【解决方案1】:

由于很多原因,无法在 Google Colaboratory 上使用 tkinter。首先,即使您设法通过关注here 使其正常工作,正如它所提到的:

但是,如果您想与 GUI 交互,那将很难,因为 Colab 不支持开箱即用的交互式屏幕。

也来自那里的其他答案:

服务器通常甚至没有显示器。即使他们有,你也不会看到它。您必须在台式机或笔记本电脑上运行 Python 才能使用 tkinter。

我无法将此问题作为重复问题关闭,因为另一个问题没有选择正确的答案。

【讨论】:

  • 更新:我通过 Anaconda -> Jupyter Notebook 在本地运行项目,设法使用了 thinker 库。
猜你喜欢
  • 1970-01-01
  • 2016-10-02
  • 2019-10-09
  • 2015-05-08
  • 2018-09-03
  • 2019-11-03
  • 1970-01-01
  • 2013-10-18
  • 2020-10-24
相关资源
最近更新 更多