I am trying to create a program then when started, shows a gif and a button that says: "Turn off system". When clicked, I want the gif to change to another gif and the button to be replaced with a button that says "Turn on system".
I made exactly this but when I click the button, the first GIF remains on the screen. You can however see the second GIF popping in and out when clicking rapidly.
EDIT* Due to a formatting issue I had to redefine my code, the def main(): you see in my code should not exist.
Here is my code:
import tkinter as tk
from PIL import Image, ImageTk
from tkinter import *
from tkinter import ttk
root = tk.Tk()
root.title('Camera System')
def update(ind):
frame = stgImg[ind]
ind += 1
if ind == frameCnt:
ind = 0
label.configure(image=frame)
root.after(100, update, ind)
def SystemOn():
stgImg = PhotoImage(file=(filename1.gif))
label.configure(image=stgImg)
label.image = stgImg
global b3
b3=tk.Button(root,text="Turn Off System",command=lambda:SystemOff())
b3.pack()
b1.pack_forget()
b2.pack_forget()
def SystemOff():
stgImg = PhotoImage(file=(filename2.gif))
label.configure(image=stgImg)
label.image = stgImg
global b2
b2=tk.Button(root,text="Turn On System",command=lambda:SystemOn())
b2.pack()
b1.pack_forget()
b3.pack_forget()
def main():
frameCnt = 12
root.geometry('1010x740+200+200')
stgImg = [PhotoImage(file=(filename1.gif),
format = 'gif -index %i' %(i)) for i in range(frameCnt)]
label=ttk.Label(root)
label.pack()
root.after(0, update, 0)
global b1
b1=tk.Button(root,text="Turn Off System",command=lambda:SystemOff())
b1.pack()
root.mainloop()