Python Forum

Full Version: from graphics import *
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am attempting to follow a tutorial however my code keeps failing in the first line.
"setBackground" and "color_rgb()" both auto filled so I know that my import has worked and it is recognizing "graphics".
However my code is still failing in the first line with this return.
Traceback (most recent call last):
File "C:/First_Try/main.py", line 1, in <module>
from graphics import *

from graphics import *
def main():
win=GraphWin("My Window",500,500)
win.setBackground(color_rgb(255,0,0))

win.getMouse()
win.close()

main()
The error message is telling you that it can't find the 'graphics' package.
there is one here: https://github.com/olls/graphics
if this is what you are trying to use, install with:
pip install graphics
then go to the URL above, read the README.md in which there are examples,
then look in the directory examples (on same web page).
While doing that pip install per Larz60+ suggestion it's worth to check Python documentation regarding import best practices: What are the “best practices” for using import in a module?. Especially:

Quote:In general, don’t use from modulename import *. Doing so clutters the importer’s namespace