Skip to content Skip to sidebar Skip to footer

Changing The Default Behavior Of Tkinter Widgets

I would like to change the default behaviors of various widgets. In particular I want to set the default relief of labels to SUNKEN, the default background to grey, the default fo

Solution 1:

I have answered my own question. As usual it is a matter of figuring out what to search for.

self.PartInputFrame.option_add("*Font","arial 32")
self.PartInputFrame.option_add("foreground","white")
self.PartInputFrame.option_add("background","blue")
self.PartInputFrame.option_add("relief","SUNKEN")

option_add is looking for a path to the option. Not the option itself. Where I set the Font, I placed a wildcard in front of it (looked right at it but never saw it). Effectively changing the Font for everything.

Where I set the 'foreground' I did not create a path.

The correct code:

self.PartInputFrame.option_add("*Font","arial 32")
self.PartInputFrame.option_add("*foreground","white")
self.PartInputFrame.option_add("*background","blue")
self.PartInputFrame.option_add("*relief","SUNKEN")

This will change foreground,background, etc, globally.

The (more) correct code:

self.PartInputFrame.option_add("*Label.Font","arial 32")
self.PartInputFrame.option_add("*Label.foreground","white")
self.PartInputFrame.option_add("*Label.background","blue")
self.PartInputFrame.option_add("*Label.relief","SUNKEN")

will change defaults for Labels (globally) ( still do not quite understand the path before *Label. When I figure that out I will amend this answer)

Post a Comment for "Changing The Default Behavior Of Tkinter Widgets"