I've got a label in tkinter that's displaying an image corresponding to a json request, however, when i try to change the image which is in the same directory as the first image i am faced with an error.
my code as follows (simplified):
class Application(tk.Tk):
def __init__(self):
super().__init__()
img_file = (r"C:\Users\Serge\Desktop\TravelApp\Assets\01d.png")
self.title("Travel Application")
self.geometry("500x300")
self.weather_image = tk.PhotoImage(file=img_file)
self.weather_image_label = tk.Label(self.box1, image=self.weather_image, width='100', height='100')
def json_Request(self, url):
try:
icon = data['weather'][0]['icon']
os.chdir(os.path.dirname(__file__))
currentDIR = os.getcwd()
img_file = (currentDIR + '\\Assets\\' + str(icon) + '.png')
self.weather_image_label.configure(image=img_file)
self.weather_image_label.image = img_file
When ever the json request comes back with the icon ID i just get an error that says:
image 'C:\Users\Serge\Desktop\TravelApp\Assets\09d.png' doesn't exist
however its in the same folder as the first image which is being displayed correctly and is named correctly. Can any one possibly tell me why my image cannot be located, Thanks