ok well I'm working on making a dungeon explorer and I can't get images to work...so far I have this

from Tkinter import *

class App:

    def __init__(self, master):

        frame = Frame(master)
        frame.pack()

        canvas = Canvas(frame, width = 225, height = 225)
        canvas.pack()

        gif1 = PhotoImage(file = 'Fhall.gif')
        canvas.create_image(0, 0, image = gif1, anchor = NW)

root = Tk()

d = App(root)

root.geometry('225x225+0+0')
root.resizable(FALSE,FALSE)
root.wait_window()

well I can't find any help on photoimage is there any sort of alternatives?

Here it is working, the image must be saved from garbage collection by saving somewhere, here we save it as variable of the canvas instanse.

from Tkinter import *

myimage = 'Fhall.gif'

class App:

    def __init__(self, master):

        frame = Frame(master)
        gif1 = PhotoImage(file = myimage)

        canvas = Canvas(frame, width = 225, height = 225)
        canvas.create_image(0, 0, image = gif1, anchor = NW)
        canvas.image = gif1 ## save image from garbage collection!
        canvas.pack()
        frame.pack()
        master.geometry('225x225+0+0')
        master.resizable(FALSE,FALSE)
        master.wait_window()
        

root = App(Tk())

I think I may have messed something up but I don't know what...I created another file to execute to shorten the coding but here are the two files

from Tkinter import *
import operator
import view

info_dict = {}
info_dict["area"] = 1
fhall = 'Fhall.gif'
fwall = 'Fwall.gif'
frhall = 'FRhall.gif'
flhall = 'FLhall.gif'
frlhall = 'FRLhall.gif'
info_dict["direction"] = "north"
class App:

    def __init__(self, master):

        frame = Frame(master)
        frame.pack()

        def start():
            if info_dict["area"] == 14:
                pic = view.view(1,0,0,0,info_dict["direction"])
                wall = view.wall(1,0,0,0,info_dict["direction"])
            if info_dict["area"] == 12 or info_dict["area"] == 20:
                pic = view.view(1,1,0,0,info_dict["direction"])
                wall = view.wall(1,1,0,0,info_dict["direction"])
            if info_dict["area"] == 21 or info_dict["area"] == 24:
                pic = view.view(1,0,1,0,info_dict["direction"])
                wall = view.wall(1,0,1,0,info_dict["direction"])
            if info_dict["area"] == 15 or info_dict["area"] == 16:
                pic = view.view(1,0,0,1,info_dict["direction"])
                wall = view.wall(1,0,0,1,info_dict["direction"])
            if info_dict["area"] == 18:
                pic = view.view(1,1,1,0,info_dict["direction"])
                wall = view.wall(1,1,1,0,info_dict["direction"])
            if info_dict["area"] == 7:
                pic = view.view(1,0,1,1,info_dict["direction"])
                wall = view.wall(1,0,1,1,info_dict["direction"])
            if info_dict["area"] == 5 or info_dict["area"] == 23 or info_dict["area"] == 25:
                pic = view.view(0,1,0,0,info_dict["direction"])
                wall = view.wall(0,1,0,0,info_dict["direction"])
            if info_dict["area"] == 3 or info_dict["area"] == 4 or info_dict["area"] == 8 or info_dict["area"] == 22:
                pic = view.view(0,1,1,0,info_dict["direction"])
                wall = view.wall(0,1,1,0,info_dict["direction"])
            if info_dict["area"] == 10:
                pic = view.view(0,1,0,1,info_dict["direction"])
                wall = view.wall(0,1,0,1,info_dict["direction"])
            if info_dict["area"] == 2 or info_dict["area"] == 9 or info_dict["area"] == 19:
                pic = view.view(0,1,1,1,info_dict["direction"])
                wall = view.wall(0,1,1,1,info_dict["direction"])
            if info_dict["area"] == 1 or info_dict["area"] == 17:
                pic = view.view(0,0,1,0,info_dict["direction"])
                wall = view.wall(0,0,1,0,info_dict["direction"])
            if info_dict["area"] == 11:
                pic = view.view(0,0,1,1,info_dict["direction"])
                wall = view.wall(0,0,1,1,info_dict["direction"])
            if info_dict["area"] == 13:
                pic = view.view(0,0,0,1,info_dict["direction"])
                wall = view.wall(0,0,0,1,info_dict["direction"])
            print pic
            print wall
            if pic == "fwall":
                info_dict["gif1"] == PhotoImage(file = fwall)
##            if pic == "fhall":
            info_dict["gif1"] == PhotoImage(file = fhall)
            if pic == "flhall":
                info_dict["gif1"] == PhotoImage(file = flhall)
            if pic == "frhall":
                info_dict["gif1"] == PhotoImage(file = frhall)
            if pic == "frlhall":
                info_dict["gif1"] == PhotoImage(file = frlhall)
            info_dict["wall"] = wall
            canvas.create_image(0, 0, image = info_dict["gif1"], anchor = NW)
            canvas.image = info_dict["gif1"]
            health.after(100, start)

        info_dict["gif1"] = PhotoImage(file = 'Fwall.gif')

        canvas = Canvas(frame, width = 225, height = 225)
        canvas.pack()

        canvas.create_image(0, 0, image = info_dict["gif1"], anchor = NW)
        canvas.image = info_dict["gif1"]

        health = Label(master, text="")
        health.after(0, start)

        def turn_left(event):
            info_dict["stop"] = "no"
            if info_dict["direction"] == "north" and info_dict["stop"] != "yes":
                info_dict["direction"] = "west"
                info_dict["stop"] = "yes"
            if info_dict["direction"] == "west" and info_dict["stop"] != "yes":
                info_dict["direction"] = "south"
                info_dict["stop"] = "yes"
            if info_dict["direction"] == "south" and info_dict["stop"] != "yes":
                info_dict["direction"] = "east"
                info_dict["stop"] = "yes"
            if info_dict["direction"] == "east" and info_dict["stop"] != "yes":
                info_dict["direction"] = "north"
                info_dict["stop"] = "yes"
            print info_dict["direction"]

        def turn_right(event):
            info_dict["stop"] = "no"
            if info_dict["direction"] == "north" and info_dict["stop"] != "yes":
                info_dict["direction"] = "east"
                info_dict["stop"] = "yes"
            if info_dict["direction"] == "east" and info_dict["stop"] != "yes":
                info_dict["direction"] = "south"
                info_dict["stop"] = "yes"
            if info_dict["direction"] == "south" and info_dict["stop"] != "yes":
                info_dict["direction"] = "west"
                info_dict["stop"] = "yes"
            if info_dict["direction"] == "west" and info_dict["stop"] != "yes":
                info_dict["direction"] = "north"
                info_dict["stop"] = "yes"
            print info_dict["direction"]

        def walk(event):
            if info_dict["direction"] == "north" and info_dict["wall"] == "no":
                info_dict["area"] = info_dict["area"] - 5
            if info_dict["direction"] == "west" and info_dict["wall"] == "no":
                info_dict["area"] = info_dict["area"] - 1
            if info_dict["direction"] == "south" and info_dict["wall"] == "no":
                info_dict["area"] = info_dict["area"] + 5
            if info_dict["direction"] == "east" and info_dict["wall"] == "no":
                info_dict["area"] = info_dict["area"] + 1

        canvas.bind("<Button-1>",turn_left)
        canvas.bind("<Button-2>",walk)
        canvas.bind("<Button-3>",turn_right)

root = Tk()

d = App(root)

root.geometry('225x225+0+0')
root.resizable(FALSE,FALSE)
root.wait_window()

and the file "view"

def view(N,W,E,S,D):
    if D == "north":
        if N != 1:
            pic = "fwall"
            wall = "yes"
        if N == 1:
            wall = "no"
            if W != 1 and E != 1:
                pic = "fhall"
            if W == 1 and E != 1:
                pic = "flhall"
            if W != 1 and E == 1:
                pic = "frhall"
            if W == 1 and E == 1:
                pic = "frlhall"
    if D == "west":
        if W != 1:
            pic = "fwall"
            wall = "yes"
        if W == 1:
            wall = "no"
            if S != 1 and N != 1:
                pic = "fhall"
            if S == 1 and N != 1:
                pic = "flhall"
            if S != 1 and N == 1:
                pic = "frhall"
            if S == 1 and N == 1:
                pic = "frlhall"
    if D == "south":
        if S != 1:
            pic = "fwall"
            wall = "yes"
        if S == 1:
            wall = "no"
            if E != 1 and W != 1:
                pic = "fhall"
            if E == 1 and W != 1:
                pic = "flhall"
            if E != 1 and W == 1:
                pic = "frhall"
            if E == 1 and W == 1:
                pic = "frlhall"
    if D == "east":
        if E != 1:
            pic = "fwall"
            wall = "yes"
        if E == 1:
            wall = "no"
            if N != 1 and S != 1:
                pic = "fhall"
            if N == 1 and S != 1:
                pic = "flhall"
            if N != 1 and S == 1:
                pic = "frhall"
            if N == 1 and S == 1:
                pic = "frlhall"
    return pic

def wall(N,W,E,S,D):
    if D == "north":
        if N != 1:
            pic = "fwall"
            wall = "yes"
        if N == 1:
            wall = "no"
            if W != 1 and E != 1:
                pic = "fhall"
            if W == 1 and E != 1:
                pic = "flhall"
            if W != 1 and E == 1:
                pic = "frhall"
            if W == 1 and E == 1:
                pic = "frlhall"
    if D == "west":
        if W != 1:
            pic = "fwall"
            wall = "yes"
        if W == 1:
            wall = "no"
            if S != 1 and N != 1:
                pic = "fhall"
            if S == 1 and N != 1:
                pic = "flhall"
            if S != 1 and N == 1:
                pic = "frhall"
            if S == 1 and N == 1:
                pic = "frlhall"
    if D == "south":
        if S != 1:
            pic = "fwall"
            wall = "yes"
        if S == 1:
            wall = "no"
            if E != 1 and W != 1:
                pic = "fhall"
            if E == 1 and W != 1:
                pic = "flhall"
            if E != 1 and W == 1:
                pic = "frhall"
            if E == 1 and W == 1:
                pic = "frlhall"
    if D == "east":
        if E != 1:
            pic = "fwall"
            wall = "yes"
        if E == 1:
            wall = "no"
            if N != 1 and S != 1:
                pic = "fhall"
            if N == 1 and S != 1:
                pic = "flhall"
            if N != 1 and S == 1:
                pic = "frhall"
            if N == 1 and S == 1:
                pic = "frlhall"
    return wall

I put some print statements so I know it's updating the picture but the image on the canvas isn't changing any help?

== is my downfall

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.