0

I want to change image when variable changed when program running image will be green when program is stopped image will be yellow. My GUI design for program states

class controller:
    
    def __init__(self,master):
        frame= Frame(master)
        frame.pack()
        
        self.isihartasi="C:/Users/Admin/Documents/Fx/dist/isiharitasi/isiharitasi.exe"
        isiharitasicheck="isiharitasi.exe" in (p.name() for p in psutil.process_iter())
        self.label=Label(frame,text="Isı Haritasi")
        self.label.pack(side=LEFT)
        self.statecheck(isiharitasicheck)
        photo =PhotoImage(file=self.statecheck(isiharitasicheck))
        label=Label(frame, image=photo)
        label.pack(side=LEFT)
        #label=Label(frame, image=self.statecheck(isiharitasicheck))
        label.pack(side=LEFT)
        
        self.isiButton=Button(frame,text="Çalıştır", command=self.run)
        self.isiButton.pack(side=RIGHT)
    def run(self):
        
        os.startfile(self.isihartasi)
        
    def statecheck(self,state):
        if state is True:
            
            file="./circle/green-circle.png"
            
        else:
            file="./circle/white-circle.png"
            
            
            return file
        
root =Tk()
b= controller(root)
root.mainloop()
  • Does this answer your question? [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function) Also the `return file` line should have the same indentation as the `if` statement in `statecheck`. – TheLizzard Sep 15 '22 at 12:39
  • `return PhotoImage(file=file)` – codester_09 Sep 15 '22 at 12:40
  • @codester_09 In this case, your suggestion isn't going to resolve the problem. – TheLizzard Sep 15 '22 at 12:42

0 Answers0