How to make a tkinter canvas background transparent?

前端 未结 1 1897
野趣味
野趣味 2020-12-06 20:13

I am making a chess program and I want to be able to drag the pieces. In order to do this, I put the image of the piece on a Canvas so it can be dragged (I can

相关标签:
1条回答
  • 2020-12-06 20:30

    Question: How to make a tkinter canvas background transparent?

    The only possible config(... option, to set the background to nothing

    c.config(bg='')
    

    results with: _tkinter.TclError: unknown color name ""


    To get this result:

    you have to hold the chess board and figures within the same .Canvas(....

        self.canvas = Canvas(self, width=500, height=200, bd=0, highlightthickness=0)
        self.canvas.create_rectangle(245,50,345,150, fill='white')
    
        self.image = tk.PhotoImage(file='chess.png')
        self.image_id = self.canvas.create_image(50,50, image=self.image)
    
        self.canvas.move(self.image_id, 245, 100)
    

    Tested with Python: 3.5 - TkVersion: 8.6

    0 讨论(0)
提交回复
热议问题