Widget configuration a label

We see here how to change the properties (attributes) of most widgets using its configuration() method.

How to do it...

Execute the program shown in the usual way.

# widget_configuration_1.py
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
from Tkinter import *
root = Tk( )
labelfont = ('times', 30, 'bold')
widget = Label(root, text='Purple and red mess with your focus')
widget.config(bg='red', fg='purple')
widget.config(font=labelfont)
widget.config(bd=6)
widget.config(relief=RAISED)
widget.config(height=2, width=40) # lines high, characters wide
widget.pack(expand=YES, fill=BOTH)
root.mainloop( )

How it works...

All widgets have default values such as a gray background, and 12 point font size. Once the code for the creation of a widget has been executed the widget appears on the screen with all its assigned properties. Further down the code, as the program is being executed, the properties of the widget can be changed using the widget.config(attribute=new value) method. The result is shown in the following screenshot:

How it works...

There's more...

Choice is good because it allows us to make our GUIs look good. The downside of this choice is that it allows us to make poor choices. But as the adage goes: poor choices made with intelligence lead to good choices.

If we run this program we will see that the combination of colors made is about the worst that can be made they interfere with the eye's focusing mechanics because the two colors have different wavelengths and follow slightly different paths on their way to the retina.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.239.226