模块对象没有属性“create_frame" [英] module object has no attribute 'create_frame'

查看:43
本文介绍了模块对象没有属性“create_frame"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些类似的问题中,这个特定问题要么没有通过建议的变通办法解决,要么问题在不同的主题上摇摆不定.因此,我不得不问这个问题:

In some of the similar questions, this particular problem is either not solved by the suggested work-arounds, or the questions have wavered to different topics. Hence, I had to ask this question :

返回的错误是:

Traceback (most recent call last):
  File "learn.py", line 8, in <module>
    frame = simplegui.create_frame("Home", 300, 200)
AttributeError: 'module' object has no attribute 'create_frame'

这是关于下面的代码

import simplegui
message = "Welcome!"
def click():
    global message
    message = "Good job!"
def draw(canvas):
    canvas.draw_text(message, [50,112], 48, "Red")
frame = simplegui.create_frame("Home", 300, 200)
frame.add_button("Click me", click)
frame.set_draw_handler(draw)
frame.start()

我已经在 Ubuntu 上使用 pip 安装了simplegui",但问题似乎仍然没有根据.请提出可能的解决方案.

I have installed the "simplegui" using pip on Ubuntu, still the problem seems unfounded. Please suggest a possible solution.

推荐答案

您遇到的问题是有两个名为 simplegui 的库.pypi 上的那个(给你错误的那个)与 codeskulptor 的那个(你有示例代码的那个).如果您想使用 codeskulptor 的示例代码,则必须在 codeskulptor 中运行您的代码.如果您想在本地计算机上运行代码,则必须放弃 codeskulptor 示例代码.

The problem you're running into is that there are two libraries called simplegui. The one on pypi (the one that's giving you the error) is totally different from the one for codeskulptor (the one for which you have example code). If you want to use codeskulptor's example code you'll have to run your code inside codeskulptor. If you want to run your code on your local computer you'll have to abandon the codeskulptor example code.

这篇关于模块对象没有属性“create_frame"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆