Reputation: 85
I made a background.gif through GIMP app. I saved it as "gif" extension but cannot see any option in GIMP for making it as gif in that program. Even worse, I just click something that "looks" the same as the tutorial does.
I see in the tutorial that background must have a gif extension. When I run my gif in IDLE python, it says my background can't be recognized. Is there something wrong with my backround.gif on the GIMP app, or my code? My code and the tutorial code seem to be the sameare same.
This is the error i got:
Traceback (most recent call last): File "C:\Users\Acer\Desktop\Stickman\stickmangame.py", line 35, in g = Game() File "C:\Users\Acer\Desktop\Stickman\stickmangame.py", line 16, in init self.bg = PhotoImage(file="background.gif") File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\tkinter_init_.py", line 3545, in init Image.init(self, 'photo', name, cnf, master, **kw) File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\tkinter_init_.py", line 3501, in init self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "background.gif"
This is my code:
from tkinter import *
import random
import time
class Game:
def __init__(self):
self.tk = Tk()
self.tk.title("Mr. Stick Man Races For The Exit")
self.tk.resizable(0,0)
self.tk.wm_attributes("-topmost", 1)
self.canvas = Canvas(self.tk, width=500, height=500, highlightthickness=0)
self.canvas.pack()
self.tk.update()
self.canvas_height = 500
self.canvas_width = 500
self.bg = PhotoImage(file="background.gif")
w = self.bg.width()
h = self.bg.height()
for x in range(0, 5):
for y in range(0, 5):
self.canvas.create_image(x * w, y * h, image=self.bg, anchor='nw')
self.sprites = []
self.running = True
def mainloop(self):
while 1:
if self.running == True:
for sprite in self.sprites:
sprite.move()
self.tk.update_idletasks()
self.tk.update()
time.sleep(0.01)
g = Game()
g.mainloop()
All of them are same as the tutorial code. I chekced it many times.
I expect the Canvas will show my background.gif.
This is the option Ii found in my GIMP app: gimp extension available
And then i just click the GIMP XCF Image. And show all files. and save it. If not like that i can't save it as GIF extenstion
Upvotes: 1
Views: 563