Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Tkinter背景不显示透明_Python 2.7_Tkinter_Tkinter Canvas - Fatal编程技术网

Python 2.7 Tkinter背景不显示透明

Python 2.7 Tkinter背景不显示透明,python-2.7,tkinter,tkinter-canvas,Python 2.7,Tkinter,Tkinter Canvas,嘿,我是python的新手。在我的代码中,每当我运行代码时都会播放一个动画gif。在adobe等中打开时,gif图像实际上是透明的。但问题是当我运行代码时。gif中包含的灰色框架。我想删除灰色,以便唯一可以看到的是我唯一的动画gif 这是我的代码: # mimic an animated GIF displaying a series of GIFs # an animated GIF was used to create the series of GIFs # with a common

嘿,我是python的新手。在我的代码中,每当我运行代码时都会播放一个动画gif。在adobe等中打开时,gif图像实际上是透明的。但问题是当我运行代码时。gif中包含的灰色框架。我想删除灰色,以便唯一可以看到的是我唯一的动画gif

这是我的代码:

# mimic an animated GIF displaying a series of GIFs
# an animated GIF was used to create the series of GIFs 
# with a common GIF animator utility

import time
from Tkinter import *

root = Tk()

imagelist = ["dog001.gif","dog002.gif","dog003.gif"]

# extract width and height info
photo = PhotoImage(file=imagelist[0])
width = photo.width()
height = photo.height()
canvas = Canvas(width=width, height=height)
canvas.create_line(0,240,640,240, fill='blue')
canvas.pack()

# create a list of image objects
giflist = []
for imagefile in imagelist:
    photo = PhotoImage(file=imagefile)
    giflist.append(photo)

# loop through the gif image objects for a while
for k in range(0, 10):
    for gif in giflist:
        canvas.delete(ALL)
        canvas.create_image(width/2.0, height/2.0, image=gif)
        canvas.update()
        time.sleep(0.1)

root.mainloop()[![enter image description here][1]][1]

如上所述,使Tkinter窗口透明是可能的,但这取决于您的操作系统

如果您在Windows上,只需在创建
根目录后添加以下行即可:

root = Tk()
# Hide the root window drag bar and close button
root.overrideredirect(True)
# Make the root window always on top
root.wm_attributes("-topmost", True)
# Define a transparent color
root.wm_attributes("-transparentcolor", '#eeefff')
然后将画布的背景色设置为上面定义的透明色:

canvas = Canvas(width=width, height=height, bg='#eeefff', highlightthickness=0)