首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python 2.7中使用simpleplot (codeskulptor)

在python 2.7中使用simpleplot (codeskulptor)
EN

Stack Overflow用户
提问于 2016-09-26 16:48:09
回答 1查看 375关注 0票数 0

我已经在我的桌面上使用了下面的导入来使用Python2.7中的simpleGUI。

代码语言:javascript
复制
try:
    import simplegui
except ImportError:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

现在,我想在框架中绘制数值。有没有办法做到这一点。我对simpleplot有疑问。

这是我的全部代码:

代码语言:javascript
复制
     # Import the module
try:
    import simplegui
except ImportError:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
    import simpleplot

# Define event handler functions
def input_handler(x):
    pass
def button_handler():
    dataset1 = {3: 5, 8: 2, 1: 3}
    dataset2 = [(1, 2), (4, 7), (2, 5), (7, 6)]
    simpleplot.plot_lines('Sample', 400, 300, 'x', 'y', [dataset1,     dataset2],   True, ['dataset1', 'dataset2'])
    pass

# Create a frame
f = simplegui.create_frame("UWB GUI",CANVAS_WIDTH, CANVAS_HEIGHT)
# Register event handlers
textField1=f.add_input("File Name", input_handler,100)

f.add_button("Filter", button_handler,100)

# Start frame and timers
f.start()
EN

回答 1

Stack Overflow用户

发布于 2016-09-27 05:26:41

您必须执行以下导入操作:

代码语言:javascript
复制
try:
    import simplegui
    import simpleplot
except ImportError:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
    import SimpleGUICS2Pygame.simpleplot as simpleplot

您可以在SimpleGUICS2Pygame的文档中查看更多信息:https://simpleguics2pygame.readthedocs.io/en/latest/Tips.html

我们的想法是尝试导入simplegui和simpleplot。如果程序在CodeSkulptor中运行,那就没问题了。如果程序使用标准Python运行,则这些导入首先失败,然后导入重命名的SimpleGUICS2Pygame版本。

P.-S:代码中的两个变量CANVAS_WIDTH和CANVAS_HEIGHT没有定义。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39698354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档