在Tkinter中使用两个图像的动画背景

时间:2018-05-25 00:43:26

标签: python python-3.x python-2.7 tkinter raspberry-pi

我希望在一段时间间隔之后连续切换两张图像(200毫秒)以获得动画闪烁/闪烁像背景中的外观。我现在只设法得到静止图像。

以下代码是主程序的子窗口,它调用函数Refresher。

主要功能:

def rad_alarm(self):

   self.alarm = Tk.Toplevel()
   self.alarm.geometry('1024x600')

   #self.alarm.title("Alert")
   vFont = tkFont.Font(family = 'Helvetica', size = 30)

   #self.center(self.alarm)
   self.alarm.overrideredirect(1)

   #self.alarm.wm_attributes('-type', 'splash');

   radfilename = PhotoImage(file = "radio1.png")
   self.alarm.background_label = Label(self.alarm, image=radfilename)
   self.alarm.background_label.pack()

   bcklbl = Label(self.alarm, text = str(bck), bg="black", fg="Yellow", font=vFont)
   bcklbl.place(x = 825, y = 300, width=140, height=40)       


   cpslbl = Label(self.alarm, text = str(counti), bg="black", fg="Yellow", font=vFont)
   cpslbl.place(x = 825, y = 445, width=140, height=40)

   dtlbl = Label(self.alarm, text = datetime.now().strftime('%Y-%m-%d %H:%M:%S'), bg="black", fg="Yellow", font=vFont)
   dtlbl.place(x = 630, y = 140, width=380, height=40)


   button=Button(self.alarm, text="Acknowledge Alarm", command=self.alarm_close, relief=FLAT, bg="black", fg="Red", font=vFont)
   button.place(x = 400, y = 510, width=380, height=80)

   dt=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

   self.conn.execute("INSERT INTO ALARMS (CPS,BCK,DT) VALUES (?,?,?)",(counti, bck, dt));


   self.conn.commit()

   self.Refresher()

动画调用函数:

   def Refresher(self):
       sleep(0.1)
       radfilename = PhotoImage(file = "radio2.png")
       self.alarm.background_label.configure(image=radfilename)
       sleep(0.1)
       radfilename = PhotoImage(file = "radio1.png")
       self.alarm.background_label.configure(image=radfilename)
       self.alarm.background_label.after(200, self.Refresher) 

正如我所说,我只在背景上拍摄静止图像,而不是闪烁/闪烁动画。知道我哪里错了吗?

0 个答案:

没有答案