5

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 :

The error returned is :

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'

This is with respect to the following code

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()

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

jamylak
  • 128,818
  • 30
  • 231
  • 230
Vishal Anand
  • 474
  • 1
  • 4
  • 17

4 Answers4

5

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.

Erin Call
  • 1,764
  • 11
  • 15
1

its probably because just like the error says there isnt an attribute in that module called create_frame

im not very familiar with simlplegui but im pretty sure it a GUI generator that uses Tkinter so you dont need to create the frame because Tk does it for you but you have to have Tkinter installed

here is an example code:

import simplegui
g = simplegui.GUI()
def buttoncallback():
    g.status("Button Clicked!")
g.button("Click me!", buttoncallback)
g.button("Click me too!", buttoncallback)
def listboxcallback(text):
    g.status("listbox select: '{0}'".format(text))
g.listbox(["one", "two", "three"], listboxcallback)
g.listbox(["A", "B", "C"], listboxcallback)
def scalecallback(text):
    g.status("scale value: '{0}'".format(text))
g.scale("Scale me!", scalecallback)
g.run()

you dont need to actually make the frame just give the information for the frame or window then Tk automatically makes a window with the given infomoation

sorry if this is confusing but i hope it helped

Serial
  • 7,925
  • 13
  • 52
  • 71
  • I thank you for the help. Yes the work-around helped, but at http://www.codeskulptor.org/docs.html, it shows that this attribute is indeed present. Actually such unfounded errors makes for really uncomfortable development, hence I want to get to the crux of the problem and solve it for good. – Vishal Anand May 28 '13 at 03:00
  • oh thats true it does say its thats interesting i tried youre code and got the same error its weird becuase i thought simplegui just made it easier to give TK the buttons listboxes etc and then Tkinter runs – Serial May 28 '13 at 03:05
  • also searching on google other people have had the same problem with the same exact code you are using (im assuming you got it from somewhere) so i dont know why it wont work if its in those docs i guess maybe there wrong – Serial May 28 '13 at 03:19
  • Thanks a lot for the help (another reply sorted it out), I guess the problem was indeed related to that. The sample code is in : http://www.codeskulptor.org – Vishal Anand May 28 '13 at 05:12
0

Sorry to necro but this is the top search result for the error mentioned above, and the solution wasn't immediately obvious to me from the replies already here.

The guide to integrating simplegui with offline projects How to integrate SimpleGUI with Python 2.7 and 3.0 shell suggests this code for both codeskulptor and offline compatability:

try:
    import simplegui
except ImportError:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

If you already have a simplegui package installed locally it won't run the exception, and will instead load a package which as mentioned above, is completely different to the codeskulptor simplegui.

This code allows your projects to run in codeskulptor as well as offline if you happen to have a package called simplegui already installed locally, without having to modify the rest of your code:

try:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
except ImportError:
    import simplegui
Community
  • 1
  • 1
Scottmeup
  • 163
  • 1
  • 6
0

It should work if you just run the second import alone:

import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

But don't forget to install Pygame and SimpleGUICS2Pygame

Cosmin Staicu
  • 1,809
  • 2
  • 20
  • 27
Rachid
  • 1
  • 1