如何使Tkinter画布透明

时间:2016-01-24 18:29:52

标签: python tkinter

在我的程序中,我试图在图像上叠加不同的画布几何图形。但是,我的问题是画布本身有一种颜色可以阻挡大部分图像。如何使此画布透明,以便只显示我绘制的几何图形?这是我的代码,以防我的解释不够。

#!/usr/bin/python
import tkinter
from tkinter import *
from PIL import Image, ImageTk

root = Tk()
root.title("Infrared Camera Interface")
root.resizable(width=FALSE, height=FALSE)



class MyApp:
  def __init__(self, parent):


    #Set the dimensions of the window
    parent.minsize(width=600, height=600)
    parent.maxsize(width=600, height=600)


    #Prepare the image object being loaded into the stream camera
    self.imgName = 'Dish.png'
    self.img = Image.open(self.imgName)
    self.img = self.img.resize((560, 450), Image.ANTIALIAS)     

    #Display the image onto the stream
    self.displayimg = ImageTk.PhotoImage(self.img)
    self.imglabel = Label(root, image=self.displayimg).place(x=0, y= 0)


    self.C = tkinter.Canvas(root, bg="white", height=560, width=450)

    coord = 10, 50, 240, 210
    arc = self.C.create_arc(coord, start=0, extent=150, fill="red")

    self.C.pack()

myapp = MyApp(root)
root.mainloop()

enter image description here

1 个答案:

答案 0 :(得分:1)

据我所知,你可以使画布透明。

但您可以直接在画布上绘制图像:canvas.create_images()