Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module object has no attribute '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 :

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.

like image 975
Vishal Anand Avatar asked May 28 '13 02:05

Vishal Anand


2 Answers

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.

like image 162
Erin Call Avatar answered Nov 07 '22 14:11

Erin Call


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

like image 21
Serial Avatar answered Nov 07 '22 14:11

Serial