如何在 Cloud9 中获取用户输入 (Python)
How to get user input in Cloud9 (Python)
我刚开始使用 Cloud9 与 Python 一起编程。
但是当我尝试使用 Tkinter 时,它给了我错误 _tkinter.TclError: no display name and no $DISPLAY environment variable
。
我应该如何在 Cloud9 中使用 Python 获取用户输入(通过设置此显示或使用其他方法)?
Cloud9 托管工作区没有图形硬件,因此您将无法运行 任何 GUI 工具包。如果您想获得用户输入,最好是 运行 一个服务器,该服务器提供可用于收集输入的基于 HTML 的表单。服务器应该监听 0.0.0.0:8080 并且可以在 http://<workspacename>-<username>.c9.io
上访问。查看 this page 以快速开始在 Cloud9 上提供 html 页面。
如果您想在 Cloud9 的 Python 程序中获取用户输入,您可以使用文本输入。 Tkinter 在 Cloud9 中不起作用,因为它无法直接与显示器上的 window 进行交互;它仅限于浏览器中的一个选项卡。在 Python 2 中使用 raw_input
,在 Python 3 中使用 input
。参见 Python: user input and commandline arguments
我刚开始使用 Cloud9 与 Python 一起编程。
但是当我尝试使用 Tkinter 时,它给了我错误 _tkinter.TclError: no display name and no $DISPLAY environment variable
。
我应该如何在 Cloud9 中使用 Python 获取用户输入(通过设置此显示或使用其他方法)?
Cloud9 托管工作区没有图形硬件,因此您将无法运行 任何 GUI 工具包。如果您想获得用户输入,最好是 运行 一个服务器,该服务器提供可用于收集输入的基于 HTML 的表单。服务器应该监听 0.0.0.0:8080 并且可以在 http://<workspacename>-<username>.c9.io
上访问。查看 this page 以快速开始在 Cloud9 上提供 html 页面。
如果您想在 Cloud9 的 Python 程序中获取用户输入,您可以使用文本输入。 Tkinter 在 Cloud9 中不起作用,因为它无法直接与显示器上的 window 进行交互;它仅限于浏览器中的一个选项卡。在 Python 2 中使用 raw_input
,在 Python 3 中使用 input
。参见 Python: user input and commandline arguments