The module object does not have the attribute 'create_frame'

In some of these issues, this particular problem is either not resolved by the proposed workarounds, or the questions fluctuate on different topics. Therefore, I had to ask this question:

Error returned:

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 applies 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 installed "simplegui" using pip on Ubuntu, but the problem seems unreasonable. Please suggest a possible solution.

+4
source share
3 answers

The problem you are facing is that there are two libraries called simplegui. The one on pypi (the one that gives you the error) is completely different from the one for codekulptor (the one for which you have code example). If you want to use code code code, you will need to run your code inside codekulptor. If you want to run your code on your local computer, you will have to abandon the code code code.

+5
source

probably because, as in the case of an error, there is no create_frame attribute in this module

im not very familiar with simlplegui, but i'm sure this is a GUI generator that uses Tkinter, so you don't need to create a frame because Tk does it for you, but you have to install Tkinter

here is a sample 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 don’t need to actually force the frame to simply provide information for the frame or window, then Tk will automatically create a window with this information

Sorry if this is confusing, but I hope this helped

+1
source

Sorry necro, but this is the best search result for the error mentioned above, and the solution was not immediately obvious to me from the answers already here.

Simplegui integration guide for stand-alone projects How to integrate SimpleGUI with the Python 2.7 and 3.0 shell offers this code for both codes and stand-alone compatibility:

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

If you already have the simplegui package installed, it will not throw an exception and instead download the package, which, as mentioned above, is completely different from codekulptor simplegui.

This code allows you to run your projects in code as well as offline if you have a package called simplegui that is already installed locally without having to change the rest of your code:

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

Source: https://habr.com/ru/post/1483061/


All Articles