Python Forum
tkinter picture importation problema
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter picture importation problema
#1
(ITS LINE 16)So I typed this code exactly how it was in the book but it still didn't work. btw I typed the name of the picture plus its file type.
from tkinter import *
import random
import time

class Game:
    def __init__(self):
        self.tk = Tk()
        self.tk.title("Mr.Stickman Races for the Exit")
        self.tk.resizable(0, 0)
        self.tk.wm_attributes("-topmost", 1)
        self.canvas = Canvas(self.tk, width=500, height=500, highlightthicknes=0)
        self.canvas.pack()
        self.tk.update()
        self.canvas_height = 500
        self.canvas_width = 500
        self.bg = PhotoImage(file='Background.gif.xcf')
        w = self.bg.width()
        h = self.gb.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.sleepp(0.01)

g = Game()
g.mainloop
Error:
Traceback (most recent call last): File "C:\Users\sheep\Desktop\Ayden's Apps\Mr.Stick Man.py", line 34, in <module> g = Game() File "C:\Users\sheep\Desktop\Ayden's Apps\Mr.Stick Man.py", line 16, in __init__ self.bg = PhotoImage(file='Background.gif.xcf') File "C:\Users\sheep\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3539, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Users\sheep\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3495, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't open "Background.gif.xcf": no such file or directory >>>
Reply
#2
Try providing the absolute path of the file.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Thumbnail picture won't show, and no error. why? Ragnar_Itachi 1 1,525 Mar-20-2023, 03:15 PM
Last Post: deanhystad
  [Tkinter] the picture disappears berckut72 1 3,437 Mar-24-2020, 08:37 PM
Last Post: berckut72
  a neat picture based on recursive number phillip1882 1 2,768 Sep-06-2018, 02:48 AM
Last Post: scidam

Forum Jump:

User Panel Messages

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