-1

I am trying to make a sprite sheet editor. I have a button where you can select an image. When I put the code in a function it doesn't work, but when it is outside a function it does work. The BrowseComputer function is what I am having a problem with

from tkinter import *
from tkinter import filedialog


#Window specs
window = Tk()
window.title("TileSplit")
window.configure(background="white")

filepath = ""


#Searches computer and displays Image
def BrowseCompter():
    filepath = filedialog.askopenfilename()
    photo = PhotoImage(file = filepath)
    print(filepath)
    SelectedImage = Label(window, image=photo, bg="White").grid(row=0,column=0)
    

#Makes a variable with information about the instruction text on the screen, Sets the text background, Text color, font and location
InstructionsLabel = Label(window, text="Please select the image you would like to split:" ,bg="white" ,font= "none 12 bold")
EmptyLabel = Label(window, text="" ,bg="white" ,font= "none 12 bold")  

#Makes a button
ImportImageButton = Button(window, text="Browse:", command=BrowseCompter)   


#Location data
InstructionsLabel.grid(row=0, column=60, sticky=E)
ImportImageButton.grid(row=3,column=0)
EmptyLabel.grid(row=1, column=0)



#Tells python to make the window
window.mainloop()
Jonathan
  • 13
  • 4

1 Answers1

-1

I think you have a typo. The function shown is actually named 'BrowseCompter'.

also you might need to change your command in the button from 'BrowseCompter' to 'BrowseCompter()'