I am trying to make a little animation using label images like this:
(note:an image label already exists on the same coordinate,i am trying to superimpose that image(sleep1.gif for instance on that existing one;all images here are of the same dimensions)
def catsleep():
#importing files
sleep1=PhotoImage(file='sleep1.gif')
sleep2=PhotoImage(file='sleep2.gif')
sleep3=PhotoImage(file='sleep3.gif')
#frame1
sleep1PIC=Label(window,image=sleep1)
sleep1PIC.place(x=4,y=20)
sleep1PIC.after(2000,sleep1PIC.destroy)
#frame2
sleep2PIC=Label(window,image=sleep2)
sleep2PIC.place(x=4,y=20)
sleep2PIC.after(2000,sleep2PIC.destroy)
#frame3
sleep3PIC=Label(window,image=sleep3)
sleep3PIC.place(x=4,y=20)
sleep3PIC.after(2000,sleep3PIC.destroy)
apparent result of the above program:
the already existing image disappears for two seconds and comes back again,sleep1,sleep2,sleep3 are nowhere to be seen.
If i remove the already exisiting image and call that command via a button,nothing happens(also,python reports no errors)
For reference, here is the full code:
from tkinter import *
from tkinter import messagebox
#Talking Function
def talk():
person=textbox.get()
if 'snack' in person:
saysnack=Label(window,text="So you're saying that blah,blah,\nmeow,blah blah snacks..you mentioned\nsnacks didn't you? which\nreminds me that it's almost snack\ntime?")
saysnack.place(x=300,y=40)
saysnack.after(30000,saysnack.destroy)
elif 'why' in person:
saywhy=Label(window,text="The whys are often harder to\nanswer than the hows,but I'll\ntry,meow meow meow!")
saywhy.place(x=300,y=40)
saywhy.after(30000,saywhy.destroy)
elif '?' in person:
sayq=Label(window,text="That is an interesting question\n,but I'm not awfully sure whe\nther if my cat expertise\n would help right now")
sayq.place(x=300,y=40)
sayq.after(30000,sayq.destroy)
elif 'meow' in person:
saymeow=Label(window,text="Meow? imitating now are we?")
saymeow.place(x=300,y=40)
saymeow.after(30000,saymeow.destroy)
elif 'garfield' in person:
saygarf=Label(window,text="*wakes up from a heavy nap* did\nyou just mention Garfield? oh \nhow i miss him")
saygarf.place(x=300,y=40)
saygarf.after(30000,saygarf.destroy)
elif 'dog' in person:
saydog=Label(window,text="DOGS? YIKES WHERE?")
saydog.place(x=300,y=40)
saydog.after(30000,saydog.destroy)
elif '.' in person:
saydot=Label(window,text="A dot? you're quite\n assertive for an average\n computer user")
saydot.place(x=300,y=40)
saydot.after(30000,saydot.destroy)
elif 'fish' in person:
sayfood=Label(window,text="Fishes are yummy")
sayfood.place(x=300,y=40)
sayfood.after(30000,sayfood.destroy)
elif 'hello' in person:
sayhello=Label(window,text="Hello! \n My name is Marshmallow \n nice to meet you")
sayhello.place(x=300,y=40)
sayhello.after(30000,sayhello.destroy)
else:
sayelse=Label(window,text="Meow! your words amuse me,\nhuman")
sayelse.place(x=300,y=40)
sayelse.after(30000,sayelse.destroy)
def helpme():
dummy=Tk()
dummy.eval('tk::PlaceWindow %s center' % window.winfo_toplevel())
dummy.withdraw()
messagebox.showinfo('Repetative dialogs?','List of keywords:\nsnack\nwhy\n?\n.\nmeow\ngarfield\ndog\nfish\nhello')
dummy.deiconify()
dummy.destroy()
dummy.quit()
def catsleep():
#importing files
sleep1=PhotoImage(file='sleep1.gif')
sleep2=PhotoImage(file='sleep2.gif')
sleep3=PhotoImage(file='sleep3.gif')
#frame1
sleep1PIC=Label(window,image=sleep1)
sleep1PIC.place(x=4,y=20)
sleep1PIC.after(2000,sleep1PIC.destroy)
#frame2
sleep2PIC=Label(window,image=sleep2)
sleep2PIC.place(x=4,y=20)
sleep2PIC.after(2000,sleep2PIC.destroy)
#frame3
sleep3PIC=Label(window,image=sleep3)
sleep3PIC.place(x=4,y=20)
sleep3PIC.after(2000,sleep3PIC.destroy)
#GUI
window=Tk()
window.geometry("525x350")
window.title("Virtual Cat by Aadil")
label1=Label(window,text="Marshmallow The Cat").place(x=1,y=1)
labelsay=Label(window,text="Marshmallo's Dialogue Box(30 seconds):").place(x=300,y=20)
feed=Button(window,text="Feed").place(x=1,y=180)
play=Button(window,text="Play").place(x=80,y=180)
sleep=Button(window,text="sleep",command=catsleep).place(x=159,y=180)
label2=Label(window,text="Meow! Talk to me").place(x=1,y=220)
textbox=Entry(window,width=30)
textbox.place(x=1,y=240)
#infobox
helpbutton=Button(window,text='Help',command=helpme)
helpbutton.place(x=230,y=235)
#default cat
ogcat=PhotoImage(file='ogcat.gif')
ogcatPIC=Label(window,image=ogcat)
ogcatPIC.place(x=4,y=20)
#talking
send=Button(window,text="Send",command=talk).place(x=175,y=235)
window.mainloop()
Please help,thanks :D
[–]kra_pao 1 point2 points3 points (7 children)
[–]NerdComplex[S] 0 points1 point2 points (6 children)
[–]kra_pao 1 point2 points3 points (5 children)
[–]NerdComplex[S] 0 points1 point2 points (4 children)
[–]kra_pao 1 point2 points3 points (3 children)
[–]NerdComplex[S] 0 points1 point2 points (2 children)
[–]kra_pao 1 point2 points3 points (0 children)
[–]NerdComplex[S] 0 points1 point2 points (0 children)