问题描述
我有一个简单的 python 脚本,它使用 tkinter 库来创建简单的表单这个脚本在 jupyer notebook 和本地机器上完美运行,但是当我想在 google colab 中运行时,它会引发以下问题
I have a simple python script which use the tkinter library to create the simple formthis script perfectly work on jupyer notebook and on local machine, but when I want to run in the google colab , it throws the following issue
/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: no display name and no $DISPLAY environment variable
我如何为这样的 GUI 脚本设置这个参数
how can I set this param for such GUI script
推荐答案
Colab 在没有附加显示器的云 VM 上运行您的代码.当代码远程运行时,像 tkinter 这样的包无法访问您自己机器的显示:您必须在本地运行代码.
Colab runs your code on a cloud VM that has no attached display. There is no way for a package like tkinter to access the display of your own machine when the code is running remotely: you'll have to run your code locally instead.
这篇关于使用 tkinter 时在 Google Colab 中设置 $DISPLAY 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!