I'm working with Tkinter and developing a program that uses a PNG image, here is my code:
from tkinter import *
from PIL import ImageTk, Image
class Application:
def __init__(self, master=None):
self.ProgramaTOP = Frame(master)
img = ImageTk.PhotoImage(Image.open("company.png"))
self.ProgramaTOP.pack()
self.msg = Label(self.ProgramaTOP, text="Teste Senha", foreground="#00338d", image= img)
self.msg["font"] = ("Univers", "12", "bold")
self.msg.pack()
self.TesteSenha = Button(self.ProgramaTOP)
self.TesteSenha["text"] = "Teste Senha"
self.TesteSenha["font"] = ("Univers", "12", "bold")
self.TesteSenha["width"] = 10
self.TesteSenha["command"] = self.ProgramaTOP.quit
self.TesteSenha.pack()
root = Tk()
Application(root)
root.mainloop()
When I try to run got this error:
File "C:\Users\lucascruz\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 2809, in open fp = builtins.open(filename, "rb") FileNotFoundError: [Errno 2] No such file or directory: 'company.png'
I know that is a path problem, how can I do to program open the image from the directory where my program is running?
In the future, this program will distribuited to other people, in other machines so the code need to be flexible for every machine, my idea is to create a folder with the stored images and the code acess this folder.
How can I do this?