Python Forum
[Tkinter] How to determine if tkinter attribute accepts color - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Tutorials (https://python-forum.io/forum-4.html)
+---- Forum: GUI tutorials (https://python-forum.io/forum-34.html)
+---- Thread: [Tkinter] How to determine if tkinter attribute accepts color (/thread-135.html)



How to determine if tkinter attribute accepts color - Larz60+ - Sep-21-2016

Hello,

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):
        pass

    def getAttributes(self, widget):
        print('widget name: {}'.format(widget.widgetName))
        keys = widget.keys()
        print('\nattributes')
        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
    gw.getAttributes(Button())
but not that activebackground or background are looking for a color.

Larz60+

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.

Larz60+


RE: How to determine if tkinter attribute accepts color - Larz60+ - Oct-02-2016

No response required