Python Forum

Full Version: How to determine if tkinter attribute accepts color
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

As most all are aware of, some of the tkinter widget attributes accept color. I'm thinking,
from a logical perspective, that there must be a way to determine programmatically if
that attribute is looking for a color.

for example tkinter Button activebackground
The following code gets most of what is needed:
from tkinter import *

class GetWidgetAttributes:
    def __init__(self, root):

    def getAttributes(self, widget):
        print('widget name: {}'.format(widget.widgetName))
        keys = widget.keys()
        for key in keys:
            print('attr: {}, curval: {}, type: {}'.format(key, widget[key], type(widget[key])))

if __name__ == '__main__':
    root = Tk()
    gw = GetWidgetAttributes(root)
    # For Example, find all attributes of Tkinter Frame
but not that activebackground or background are looking for a color.


Update: 8:14 P.M. EST

I don't like this, but guess I'll use a hack looking for foreground, background and whatever else uses a color value
I've been looking at the tkinter source, and I don't see anything that indicates the category of attribute expected. As
one final attempt, I'll examine the tk C code. It would be better to find some other way to do this.

No response required