Reputation: 1
For the following code snippet:
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'm getting error message on create_frame, "undefined variable from import:create_frame". Can anyone tell me what the problem is? simplegui is already imported and the code is given by a reputed university website.
Upvotes: 0
Views: 2714
Reputation: 31
If you want to use simplegui out side of codeskulptor you can download it with your terminal with the command: sudo pip install SimpleGUITk Then you can import it with: import simpleguitk ... also just a heads up I've only found simplegui to work with python 2.7. Hope this helps!!
Upvotes: 0
Reputation: 1784
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.
Upvotes: 2