【发布时间】:2016-01-27 08:06:02
【问题描述】:
from tkinter import *
from time import *
import os
class gui(Canvas):
def _init_(self,parent):
Canvas.__init__(self,parent)
self.pack(fill=BOTH)
root.protocol("WM_DELETE_WINDOW"", self.close)
def image(self):
self.giflist=[]
self.imagelist=[All frames of the gif image]
for image in self.imagelist:
self.photo=PhotoImage(file=image)
self.giflist.append(self.photo)
self.label=Label(self,fg="black",font=("arial",20,"italic"))
self.label1=Label(self,bd=0)
def Run(self):
for gif in self.giflist:
self.delete(ALL)
self.label.config(text=asctime)
self.label.text=asctime()
self.label.pack()
self.label1.config(image=gif)
self.label1.image=gif
self.label1.pack()
self.update()
sleep(0.1)
def close(self):
os._exit(0)
root=Tk()
frame=Canvas(root)
g=gui(frame)
g.image()
while True:
g.Run()
root.mainloop()
执行代码时,tkinter 窗口为空白。我知道在不使用类的情况下放置 gif 图像,但我想知道这段代码有什么问题。
如果它太明显或太简单,我很抱歉。我正在使用 Python 3.5。
下面给出了放置gif图像的代码。
from tkinter import *
from time import *
root=Tk()
frame=Canvas(root)
frame.pack()
imagelist=[All frames of gif image]
giflist=[]
for image in imagelist:
photo=PhotoImage(file=image)
giflist.append(photo)
l=Label(frame,bd=0)
while True:
for gif in giflist:
l.config(image=gif)
l.image=gif
l.pack()
sleep(0.1)
frame.update()
root.mainloop()
【问题讨论】:
-
"我知道不使用类就放 gif 图像"。你是说你有一个不使用类的工作版本吗?你也能证明吗?我很难确定这段代码要做什么。
-
当您说“运动图像”时,您的意思是希望图像在屏幕上移动,还是“运动图像”的意思是“像电影一样播放一系列图像”?
-
@Kevin 是的,我今天会发给你它的链接
-
@Bryan Oakley 我的意思是像电影一样播放一系列图像
-
@Kevin m.youtube.com/… 检查第一个窗口的代码。在那里你会发现如何放置动态 gif 图像。否则,如果您愿意,我将向您发送仅用于放置 gif 图像的代码
标签: python class canvas tkinter gif