my problem is that I don't know how to update an image button the location for the image is stored in a text file but even if I reopen the file the button does not update I also tried deleting the button and adding it back but that also didn't work thanks for your help and time.
#imports
from ast import Lambda
from cProfile import label
from fileinput import filename
from tkinter import Entry, filedialog
from tkinter import *
import os
import shutil
from PIL import ImageTk , Image
import time
#define the first tk window
window = Tk()
window.geometry("655x600")
window.title("streamdex")
window.resizable(False, False)
icon = PhotoImage(file="data/icons/venkuicon.png")
window.iconphoto(True,icon)
window.config(background="#2e3033")
def save_data12(data):
with open("data/userinput/data12.txt", "w", encoding="utf-8") as file:
file.write(data)
global file12
with open("data/image_input/data12.txt", 'r') as file12:
imgdata12 = file12.read().replace('\n', '')
def new_window12():
window13 = Toplevel()
window13.geometry("500x100+200+300")
window13.config(background="#2e3033")
window13.title("Edit Button 12")
Button12 = Button(window13, text="save",command=lambda: [save_data12(entry12.get()),window13.destroy()])
Button12.place(x=5,y=70)
entry12 = Entry(window13,width=100, font= ("Arial",12))
entry12.place(x=5,y=30)
browse_button12 = Button(window13, text="Change image", command=lambda: [browser12(), window13.destroy()])
browse_button12.place(x=50, y=70)
streamdex_image12 = PhotoImage(file=imgdata12)
streamdex_button12 = Button(window, text="hello" , command=new_window12 , image=streamdex_image12)
streamdex_button12.place(x=500,y=380)
file12.close()
with open("data/image_input/data12.txt", 'r') as file:
imgdata12 = file.read().replace('"', '')
def change():
streamdex_button12.place_forget()
time.sleep(0.1)
streamdex_button12.place(x=500,y=380)
def browser12():
filepath = filedialog.askopenfilename(initialdir=os.getcwd(), title="select an Image File" ,filetypes=(("PNG File","*.png"),("JPG File", "*.jpg")))
with open("data/image_input/data12.txt", "w", encoding="utf-8") as file:
file.write(filepath)
change()
window.mainloop()
If this is the code you are referring to, it only executes when the program starts because of the indent. Although it will read the same thing if run a second time. There is no way to tell which part of the program you mean based on the description.