Skip to main content

Section 15.9 Common Widget Properties

Each widget has a set of properties that define its visual appearance on the computer screen and how it responds to user events. There is a set of properties that all tk widgets have in common. Some of these are shown in the following table.

Remember that ttk widgets match the “look and feel” of the computer that is running your program, so there are limited attributes you can change for ttk widgets. See the ttk style attribute information at https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/ttk-style-layer.html 1  if you want to modify ttk widgets.)

Table 15.9.1.
Common Widget Properties Description
bg Background color.
fg Foreground color.
width Width in pixels
height Height in pixels
borderwidth The size of the border in pixels.
text Text displayed on the widget.
font The font used for text on the widget.
cursor The shape of the cursor when the cursor is over the widget.
activeforeground The color of the text when the widget is activated.
activebackground The color of the background when the widget is activated.
image An image to be displayed on the widget.

You can treat a widget object as a dictionary and use the property names as keys to access and change the property values. For example, to change the background color and width of a widget whose object variable is named sam, you could do this:

sam = tk.Button(application_window, text="Sam's Button")
sam['bg'] = 'red'
sam['width'] = 60  # pixels
You have attempted of activities on this page.
https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/ttk-style-layer.html