How do I get the background color of a Tkinter Canvas widget

python, tkinter

Solution

You should be able to access the color through `myCanvas["background"]`

myCanvas.create_rectangle( x0, y0, x1, y1, outline=myCanvas["background"], fill=myCanvas["background"])

Problem

I need to create a rectangle in a Canvas widget using the background color as the fill color. I don't care what color the background of the Canvas is, I just want to get the color. So the relevant bit of code would look like this: ``` myCanvas.create_rectangle(x0, y0, x1, y1, outline=myCanvas.bgcolor(), fill=myCanvas.bgcolor()) ``` Where naturally `myCanvas.bgcolor()` is what I'm after. I've seen lots of examples of setting this and other parameters, but none for getting.

Original source