Reputation: 21
I do not know where is the directory to put the images in to make the background of the game I am making please help!
this is the 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="backround.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() time.sleep(0.01) g = Game() g.mainloop()
and this is the error I get...
Traceback (most recent call last):
File "C:\Users\user\Desktop\Mr.Stickman Races To The Exit!.py", line 37, in <module>
g = Game()
File "C:\Users\user\Desktop\Mr.Stickman Races To The Exit!.py", line 19, in __init__
self.bg = PhotoImage(file="backround.gif")
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 4063, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 4008, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "backround.gif": no such file or directory
i have put the background image in the tkinter library but the same error shows up I hope someone can help me on this Thanks
Upvotes: 0
Views: 322
Reputation: 411
You don't put image in Tkinter Library
Bring the picture to your script folder
Make sure your filename is same with the program
Upvotes: 1