Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
from graphics import *
#1
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()
Reply
#2
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).
Reply
#3
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python graphics kaltenherz 1 1,681 Sep-05-2021, 05:19 PM
Last Post: jefsummers
  Graphics py not found vnc 13 21,163 Apr-05-2017, 05:36 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020