如何将 SimpleGUI 与 Python 2.7 和 3.0 shell 集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16387770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to integrate SimpleGUI with Python 2.7 and 3.0 shell
提问by Tahmeedbuet
I am learning Python from Coursera. In this course they use SimpleGUImodule on CodeSkulptor. Can anyone tell me how to integrate SimpleGUI with python 2.7 and 3.0 shell?
我正在从 Coursera 学习 Python。在本课程中,他们在CodeSkulptor上使用SimpleGUI模块。谁能告诉我如何将 SimpleGUI 与 python 2.7 和 3.0 shell 集成?
采纳答案by Yoriz
From the coursera forums by Darren Gallagher
来自 Darren Gallagher 的 coursera 论坛
From the CodeSkulptor Documentation:
http://www.codeskulptor.org/docs.html
"... implements a subset of Python 2.6...CodeSkulptor's Python is not a subset in one respect...Implemented on top of JavaScript..."
I don't think that CodeSkulptor / SimpleGUI is a Python Module, as we know it. It is written on top of Javascript to allow the user output to their web browser, as opposed to their desktop and/or interpreter window.
The module I have found / used in Python that is most similar to SimpleGUI is Pygame - in both syntax and display. It requires a little more to get a project 'running' but is definitely worth investing time in. I'm sure what we will learn in the coming weeks with SimpleGUI will be very transferable.
来自 CodeSkulptor 文档:
http://www.codeskulptor.org/docs.html
“……实现了 Python 2.6 的一个子集……CodeSkulptor 的 Python 不是一个方面的子集……在 JavaScript 之上实现……”
正如我们所知,我不认为 CodeSkulptor / SimpleGUI 是一个 Python 模块。它写在 Javascript 之上,允许用户输出到他们的 Web 浏览器,而不是他们的桌面和/或解释器窗口。
我在 Python 中发现/使用的与 SimpleGUI 最相似的模块是 Pygame——在语法和显示上。让项目“运行”需要更多的时间,但绝对值得投入时间。我相信我们在接下来的几周内将通过 SimpleGUI 学到的东西将是非常可转移的。
The full thread can be found here Can the staff give us the SIMPLEGUI module?(Note need to be enrolled to the course to view the link)
完整的线程可以在这里找到 工作人员可以给我们 SIMPLEGUI 模块吗?(注意需要注册课程才能查看链接)
A python package called SimpleGUICS2Pygame has since been created to run CodeSkulptor code using Pygame, I haven't tried it myself yet but it can be foundhere
此后创建了一个名为 SimpleGUICS2Pygame 的 python 包来使用 Pygame 运行 CodeSkulptor 代码,我自己还没有尝试过,但可以在这里找到
回答by Mike Driscoll
I don't see any information on PyPIabout which versions of Python simpleGUI supports. You can just try running it with Python 3 and see what happens. If it doesn't work, try using the 2to3 tools: http://docs.python.org/2/library/2to3.html
我在PyPI上没有看到关于 Python simpleGUI 支持哪些版本的任何信息。您可以尝试使用 Python 3 运行它,看看会发生什么。如果它不起作用,请尝试使用 2to3 工具:http: //docs.python.org/2/library/2to3.html
Note that simpleGUI is based on Tkinter. I would recommend learning a full GUI toolkit like Tkinter, wxPython or PySide rather than a derivative.
请注意,simpleGUI 基于 Tkinter。我建议学习一个完整的 GUI 工具包,比如 Tkinter、wxPython 或 PySide,而不是衍生工具。
回答by Marc
SimpleGUITk can be used in Python 3.
SimpleGUITk 可以在 Python 3 中使用。
The Problem is simplegui.py
问题是 simplegui.py
Just install SimpleGUITk as described in the README of the package.
只需按照包的自述文件中的描述安装 SimpleGUITk。
Then modify the simplegui.py file in the python33 folder with an text-editor.
然后用文本编辑器修改python33文件夹中的simplegui.py文件。
In the file are some calls for Tkinter. Just replace Tkinter with tkinter and everything is fine and the example in the readme runs without errors.
文件中有一些对 Tkinter 的调用。只需用tkinter替换Tkinter ,一切都很好,自述文件中的示例运行没有错误。
(I also make a Coursera course. But the SimpleGUI module is not the simplegui used in CodeSkulptor. Sorry, so you can't write programs for CodeSkulptor in IDLE with this lib)
(我也做了一个 Coursera 课程。但 SimpleGUI 模块不是 CodeSkulptor 中使用的 simplegui。抱歉,所以你不能用这个 lib 在 IDLE 中为 CodeSkulptor 编写程序)
回答by Pedro Guerreiro
You can just use SimpleGUITk (http://pypi.python.org/pypi/SimpleGUITk) which implements a Tk version of simplegui.
您可以使用 SimpleGUITk ( http://pypi.python.org/pypi/SimpleGUITk),它实现了 simplegui 的 Tk 版本。
To use your CodeSkulptor code in the desktop, you just need to replace
要在桌面上使用您的 CodeSkulptor 代码,您只需要替换
import simplegui
with
和
import simpleguitk as simplegui
and that's it, your program made for CodeSkulptor code should work on the desktop.
就是这样,您为 CodeSkulptor 代码编写的程序应该可以在桌面上运行。
回答by Md Rashedul Hoque Bhuiyan
I just installed simpleguitk to enable simplegui on my os. I am using linuxmint 15. Steps are:
我刚刚安装了 simpleguitk 来在我的操作系统上启用 simplegui。我正在使用 linuxmint 15。步骤是:
First download simpleguitk from this link simpleguitk. In order to work with simplegui perfectly you have to install these packages
首先从这个链接simpleguitk下载simpleguitk。为了完美地与 simplegui 一起工作,你必须安装这些包
Pillow in order to use images.
Pygame for sound support
matplotlib for SimplePlot support.
枕头以使用图像。
Pygame 用于声音支持
matplotlib 用于 SimplePlot 支持。
You can install Pygame by suing this command :
sudo apt-get install python-pygameYou can install matplotlib by using this command :
sudo apt-get install python-matplotlibTo install Pillow , download zip file from this link Pillow
Unzip it and change directory to Pillow. Then use this command
python setup.py install (assuming you've already installed python.h or you can install it usingsudo apt-get install python.hFinally you have to install simpleguitk . Before installing it i suggest you to install this module setuptools.
you can install setuptools using this command :
sudo apt-get install python-setuptoolsNow Extract simpleguitk on your home directory. Then change directory to simpleguitk folder.
After that use this command :
python setup.py install
您可以通过使用以下命令来安装 Pygame:
sudo apt-get install python-pygame您可以使用以下命令安装 matplotlib:
sudo apt-get install python-matplotlib要安装 Pillow ,请从此链接Pillow下载 zip 文件
解压缩并将目录更改为 Pillow。然后使用这个命令
python setup.py install (假设你已经安装了 python.h 或者你可以使用sudo apt-get install python.h最后你必须安装 simpleguitk 。在安装它之前,我建议你安装这个模块 setuptools。
您可以使用以下命令安装 setuptools:
sudo apt-get install python-setuptools现在在您的主目录中提取 simpleguitk。然后将目录更改为 simpleguitk 文件夹。
之后使用此命令:
python setup.py install
Type pythonon terminal
类型python的终端
Import simpleguitk as simplegui
将 simpleguitk 导入为 simplegui
回答by Olivier Pirson
You can use my
你可以用我的
SimpleGUICS2Pygamepackage.
SimpleGUICS2Pygame包。
Objectively, this is the best solution :-)
客观地说,这是最好的解决方案:-)
The package implement simplegui, codeskulptor, numericand simpleplotmodules.
该包实现simplegui、codeskulptor、numeric和simpleplot模块。
Ifyour Python tools are up to date, it is easy to install:
如果您的 Python 工具是最新的,则很容易安装:
python -m pip install SimpleGUICS2Pygame --user --upgrade
- Online HTML documentation: https://simpleguics2pygame.readthedocs.io/
- Sources: https://bitbucket.org/OPiMedia/simpleguics2pygame
- 在线 HTML文档:https: //simpleguics2pygame.readthedocs.io/
- 来源:https: //bitbucket.org/OPiMedia/simpleguics2pygame
In your code, replace the import command
在您的代码中,替换导入命令
import simplegui
by
经过
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
and your code run in CodeSkulptor andin standard Python (2 and3) with this package.
并且您的代码使用此包在 CodeSkulptor和标准 Python(2和3)中运行。
Note that:
注意:
- SimpleGUITkis an otherimplementation, using Tkinter and some others packages. It is really less complete and not updated. However it works for some programs.
- simpleguiis a Python package which has the same name as SimpleGUI of CodeSkulptor, but it is totally something else.
- SimpleGUITk是另一种实现,使用 Tkinter 和其他一些包。它真的不太完整,没有更新。但是它适用于某些程序。
- simplegui是一个Python包具有相同的名称作为CodeSkulptor的SimpleGUI,但它完全是别的东西。
回答by Olivier Pirson
Note: Steps is for windows
注意:步骤适用于windows
The replacement for simplegui is SimpleGUICS2Pygame.
Steps to install:
-
Step 1: Install Python 2.7 and Simpleguics2Pygame from : https://pypi.python.org/packages/source/S/SimpleGUICS2Pygame/SimpleGUICS2Pygame-01.08.00.tar.gz#md5=e4a18fe83e4a64c6222bfb71349be31e
Step 2: Extract it to a location (Lets call it somewhere)
Step 3: Open command prompt as administrator and change directory using the command
cd somewhere/SimpleGUICS2Pygame-01.08.00.
Step 4: Run the command setup.py install
simplegui 的替代品是 SimpleGUICS2Pygame。
安装步骤: -
第 1 步:从以下位置安装 Python 2.7 和 Simpleguics2Pygame:https
: //pypi.python.org/packages/source/S/SimpleGUICS2Pygame/SimpleGUICS2Pygame-01.08.00.tar.gz#md5=e4a18fe83e4a24b3e3e Step3e3e24c62Extract它到一个位置(让我们称之为某个地方)
步骤 3:以管理员身份打开命令提示符并使用命令
cd 某处/SimpleGUICS2Pygame-01.08.00更改目录。
第 4 步:运行命令 setup.py install
SimpleGUICS2Pygame is now installed and can now be accessed using the following code instead of import simplegui:
SimpleGUICS2Pygame 现在已安装,现在可以使用以下代码而不是以下代码进行访问import simplegui:
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

