Python Forum
Error trying to draw a gif with graphics.py - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: Error trying to draw a gif with graphics.py (/thread-10621.html)



Cant draw a image Help - fierygaming - May-28-2018

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


RE: Cant draw a image Help - j.crater - May-28-2018

Please put your code in Python code tags and full error traceback message in error tags. You can find help here.


RE: Cant draw a image Help - fierygaming - May-28-2018

(May-28-2018, 05:21 PM)j.crater Wrote: Please put your code in Python code tags and full error traceback message in error tags. You can find help here.

My apologizes but i believe I cant edit this as im just a user and not a member


Error trying to draw a gif with graphics.py - fierygaming - May-28-2018

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.

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)
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



RE: Error trying to draw a gif with graphics.py - Larz60+ - May-28-2018

you don't need line 1 as lines 2 and 3 load all
You have no indentation after line 48.
functions, methods, iterators need indentation (4 spaces per level)


RE: Error trying to draw a gif with graphics.py - fierygaming - May-29-2018

Thank you very much I appreciate it!


RE: Error trying to draw a gif with graphics.py - fierygaming - May-29-2018

(May-28-2018, 08:48 PM)Larz60+ Wrote: you don't need line 1 as lines 2 and 3 load all
You have no indentation after line 48.
functions, methods, iterators need indentation (4 spaces per level)

This didnt work. Could you provide an example of what you mean because I may be doing it wrong or misunderstanding you


RE: Error trying to draw a gif with graphics.py - Larz60+ - May-29-2018

you show code as :
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)
needs to be indented
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)
The code may still be bad, but you need this indentation

on import you only need:
from graphics import*
from pygame import*
But I wouldn't do it this way (for future reference) better to import what you specifically need


RE: Error trying to draw a gif with graphics.py - fierygaming - May-29-2018

(May-29-2018, 05:28 PM)Larz60+ Wrote: you show code as :
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)
needs to be indented
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)
The code may still be bad, but you need this indentation

on import you only need:
from graphics import*
from pygame import*
But I wouldn't do it this way (for future reference) better to import what you specifically need

Ohhhh..... Yay all my stuff is indented properly I just forgot to do it here so that not the issue. im really confused now, I have done this before and im looking back on it and im doing the same here as i did there and there are no issues. But yet there is issues here for some reason.