Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

tkinter

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.

like image 656
Component 10 Avatar asked Jun 20 '12 12:06

Component 10


1 Answers

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

myCanvas.create_rectangle( x0, y0, x1, y1, outline=myCanvas["background"], fill=myCanvas["background"])
like image 129
smont Avatar answered Sep 26 '22 12:09

smont