Python Forum
[Tkinter] How to determine if tkinter attribute accepts color
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to determine if tkinter attribute accepts color

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

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020