Python Forum
Problem with absolute path to file (Mr.Stickman Problems)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with absolute path to file (Mr.Stickman Problems)
#1
Right now I'm working on getting the backround. So I ran into a problem and someone said to provide the absolute value of the file of the picture so I did that but it still doesnt work can someone please tell me whats wrong with it.
from tkinter import *
import random
import time
import os

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=os.path.abspath('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 35, in <module> g = Game() File "C:\Users\sheep\Desktop\Ayden's Apps\Mr.Stick Man.py", line 17, in __init__ self.bg = PhotoImage(file=os.path.abspath('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 "C:\Users\sheep\Desktop\Ayden's Apps\Background.gif.xcf": no such file or directory >>>
Reply


Messages In This Thread
Problem with absolute path to file (Mr.Stickman Problems) - by SheeppOSU - Jun-26-2018, 01:16 AM
RE: Mr.Stickman Problems - by woooee - Jun-26-2018, 05:13 AM
RE: Mr.Stickman Problems - by buran - Jun-26-2018, 06:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute paths in subprocess - file not found kittyticker 4 482 Jan-28-2024, 10:37 PM
Last Post: kittyticker
Sad problems with reading csv file. MassiJames 3 619 Nov-16-2023, 03:41 PM
Last Post: snippsat
  File path by adding various variables Mishal0488 2 1,026 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Script File Failure-Path Error? jerryf 13 3,450 Nov-30-2022, 09:58 AM
Last Post: jerryf
  Upgrading from 2 to 3 and having file write problems KenHorse 2 1,478 May-08-2022, 09:47 PM
Last Post: KenHorse
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,203 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  (Path?)Problems with dockerizing a python app sgofferj 0 1,626 Jul-19-2021, 10:02 AM
Last Post: sgofferj
Exclamation Path sacn problem lucky511 10 3,876 Jun-24-2021, 12:09 PM
Last Post: Axel_Erfurt
  Problems with inserting images into an Excel File FightingFarmer 2 3,403 May-12-2021, 10:03 PM
Last Post: FightingFarmer
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,002 May-07-2021, 03:26 PM
Last Post: herwin

Forum Jump:

User Panel Messages

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