简体   繁体   English

如何将 SimpleGUI 与 Python 2.7 和 3.0 shell 集成

[英]How to integrate SimpleGUI with Python 2.7 and 3.0 shell

I am learning Python from Coursera.我正在从 Coursera 学习 Python。 In this course they use SimpleGUI module on CodeSkulptor .在本课程中,他们在CodeSkulptor上使用SimpleGUI模块。 Can anyone tell me how to integrate SimpleGUI with python 2.7 and 3.0 shell?谁能告诉我如何将 SimpleGUI 与 python 2.7 和 3.0 shell 集成?

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 代码编写的程序应该可以在桌面上运行。

You can use my你可以用我的

在此处输入图片说明SimpleGUICS2Pygame package. SimpleGUICS2Pygame包。

Objectively, this is the best solution :-)客观地说,这是最好的解决方案:-)

The package implement simplegui , codeskulptor , numeric and simpleplot modules.该包实现simpleguicodeskulptornumericsimpleplot模块。

If your Python tools are up to date, it is easy to install:如果您的 Python 工具是最新的,则很容易安装:

python -m pip install SimpleGUICS2Pygame --user --upgrade

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 and in standard Python (2 and 3) with this package.并且您的代码使用此包在 CodeSkulptor标准 Python(23)中运行。

Note that:注意:

  • SimpleGUITk is an other implementation, using Tkinter and some others packages. SimpleGUITk一种实现,使用 Tkinter 和其他一些包。 It is really less complete and not updated.它真的不太完整,没有更新。 However it works for some programs.但是它适用于某些程序。
  • simplegui is a Python package which has the same name as SimpleGUI of CodeSkulptor, but it is totally something else . simplegui是一个Python包具有相同的名称作为CodeSkulptor的SimpleGUI,但它完全是另一回事

From the coursera forums by Darren Gallagher来自 Darren Gallagher 的 coursera 论坛

From the CodeSkulptor Documentation:来自 CodeSkulptor 文档:

http://www.codeskulptor.org/docs.html 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..." “……实现了 Python 2.6 的一个子集……CodeSkulptor 的 Python 不是一个方面的子集……在 JavaScript 之上实现……”

I don't think that CodeSkulptor / SimpleGUI is a Python Module, as we know it.正如我们所知,我不认为 CodeSkulptor / SimpleGUI 是一个 Python 模块。 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.它写在 Javascript 之上,允许用户输出到他们的 Web 浏览器,而不是他们的桌面和/或解释器窗口。

The module I have found / used in Python that is most similar to SimpleGUI is Pygame - in both syntax and display.我在 Python 中发现/使用的与 SimpleGUI 最相似的模块是 Pygame——在语法和显示上。 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.让项目“运行”需要更多的时间,但绝对值得投入时间。我相信我们在接下来的几周内将通过 SimpleGUI 学到的东西将是非常可转移的。

The full thread can be found here Can the staff give us the SIMPLEGUI module?完整的线程可以在这里找到工作人员可以给我们 SIMPLEGUI 模块吗? ( Note need to be enrolled to the course to view the link ) 注意需要注册课程才能查看链接


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 found here此后创建了一个名为 SimpleGUICS2Pygame 的 Python 包,用于使用 Pygame 运行 CodeSkulptor 代码,我自己还没有尝试过,但可以在此处找到

I just installed simpleguitk to enable simplegui on my os.我刚刚安装了 simpleguitk 来在我的操作系统上启用 simplegui。 I am using linuxmint 15. Steps are:我正在使用 linuxmint 15。步骤是:

First download simpleguitk from this link simpleguitk .首先从这个链接simpleguitk下载simpleguitk In order to work with simplegui perfectly you have to install these packages为了完美地与 simplegui 一起工作,你必须安装这些包

Pillow in order to use images.枕头以使用图像。
Pygame for sound support用于声音支持的 Pygame
matplotlib for SimplePlot support.用于 SimplePlot 支持的 matplotlib。

  1. You can install Pygame by suing this command :您可以通过使用以下命令来安装 Pygame:

     sudo apt-get install python-pygame
  2. You can install matplotlib by using this command :您可以使用以下命令安装 matplotlib:

     sudo apt-get install python-matplotlib
  3. To install Pillow , download zip file from this link Pillow要安装 Pillow ,请从此链接Pillow下载 zip 文件

    Unzip it and change directory to Pillow.解压缩并将目录更改为 Pillow。 Then use this command然后使用这个命令
    python setup.py install (assuming you've already installed python.h or you can install it using python setup.py install (假设你已经安装了 python.h 或者你可以使用

    sudo apt-get install python.h
  4. Finally you have to install simpleguitk .最后你必须安装 simpleguitk 。 Before installing it i suggest you to install this module setuptools.在安装它之前,我建议你安装这个模块 setuptools。

    you can install setuptools using this command :您可以使用以下命令安装 setuptools:

     sudo apt-get install python-setuptools

    Now Extract simpleguitk on your home directory.现在在您的主目录中提取 simpleguitk。 Then change directory to simpleguitk folder.然后将目录更改为 simpleguitk 文件夹。

    After that use this command :之后使用此命令:

     python setup.py install

Type python on terminal在终端输入python

Import simpleguitk as simplegui将 simpleguitk 导入为 simplegui

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.文件中有一些对 Tkinter 的调用。 Just replace T kinter with t kinter and everything is fine and the example in the readme runs without errors.只需用t kinter 替换T kinter ,一切都很好,自述文件中的示例运行没有错误。

(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 编写程序)

Note: Steps is for windows注意:步骤适用于windows

The replacement for simplegui is SimpleGUICS2Pygame. simplegui 的替代品是 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第 1 步:从以下位置安装 Python 2.7 和 Simpleguics2Pygame: https ://pypi.python.org/packages/source/S/SimpleGUICS2Pygame/SimpleGUICS2Pygame-01.08.00.tar.gz#md5=e4a18fe83e4a64c6222bfb71e
Step 2: Extract it to a location (Lets call it somewhere)第 2 步:将其提取到某个位置(让我们将其称为某处)
Step 3: Open command prompt as administrator and change directory using the command第 3 步:以管理员身份打开命令提示符并使用命令更改目录
cd somewhere/SimpleGUICS2Pygame-01.08.00. cd 某处/SimpleGUICS2Pygame-01.08.00。
Step 4: Run the command setup.py install第 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

I don't see any information on PyPI about which versions of Python simpleGUI supports.我在PyPI上没有看到关于 Python simpleGUI 支持哪些版本的任何信息。 You can just try running it with Python 3 and see what happens.您可以尝试使用 Python 3 运行它,看看会发生什么。 If it doesn't work, try using the 2to3 tools: http://docs.python.org/2/library/2to3.html如果它不起作用,请尝试使用 2to3 工具: http : //docs.python.org/2/library/2to3.html

Note that simpleGUI is based on Tkinter.请注意,simpleGUI 基于 Tkinter。 I would recommend learning a full GUI toolkit like Tkinter, wxPython or PySide rather than a derivative.我建议学习一个完整的 GUI 工具包,比如 Tkinter、wxPython 或 PySide,而不是衍生工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM