Python Forum
Error trying to draw a gif with graphics.py
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error trying to draw a gif with graphics.py
#1
Hey guys im sort of a noob at python and im really struggling with this. Im try to draw a image in a function but for some reason it doesnt work I dont know why please help I have the image in the same folder as my code.
Code:

import graphics,pygame
from graphics import*
from pygame import*

##Variables##
x,y=0,0 #positions of mouse clicks
p1 = GraphWin("Tut",1440,900)
exit1 = Rectangle(Point(40,40),Point(10,10))
start1 = Rectangle(Point(200,200),Point(100,100))
txt1 = Text(exit1.getCenter(),'Exit')
p=p1.checkMouse()
choices,error=0,0

##Program##
choices=Text(Point(p1.getWidth()/2,p1.getHeight()/2 +50),'Enter f to continue')
choices.setTextColor('white')
choices.setSize(24)
choices.draw(p1)
entry1=Entry(Point(p1.getWidth()/2, p1.getHeight()/2+100),1)
entry1.draw(p1)
error=Text(Point(p1.getWidth()/2,300),'You need to enter a correct choice.')
#_______________________________________________________________#
##Exit Button##

p1.setBackground('blue')

exit1.draw(p1)
exit1.setFill('Red')
exit1.setWidth(1)
txt1.draw(p1)

while True:
p=p1.checkMouse()
if p:
x=p.getX()
y=p.getY()
print(x,y)
if 10<x<40 and 10<y<40 :
p1.close()
elif p:
break
#_______________________________________________________________#
##Picture##
def Fight():
pic=Image(Point(p1.getWidth()/2,p1.getHeight()/2),'Ion.gif')
pic.draw(p1)

while True:
p1.getMouse()
choice=entry1.getText()
if choice=="f":
choices.undraw()
entry1.undraw()
error.undraw()
Fight()
break
else:
error.setTextColor('white')
error.setSize(24)
error.draw(p1)

Here is the error:
Traceback (most recent call last):
File "H:\Python Coding\tut.py", line 58, in <module>
Fight()
File "H:\Python Coding\tut.py", line 48, in Fight
pic=Image(Point(p1.getWidth()/2,p1.getHeight()/2),'Ion.gif')
File "H:\Python Coding\graphics.py", line 885, in __init__
self.img = tk.PhotoImage(file=pixmap[0], master=_root)
File "C:\Python32\lib\tkinter\__init__.py", line 3287, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python32\lib\tkinter\__init__.py", line 3243, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "Ion.gif": no such file or directory
Reply


Messages In This Thread
Cant draw a image Help - by fierygaming - May-28-2018, 03:54 PM
RE: Cant draw a image Help - by j.crater - May-28-2018, 05:21 PM
RE: Cant draw a image Help - by fierygaming - May-28-2018, 05:30 PM

Forum Jump:

User Panel Messages

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