![]() Use the Style.element_options() method to get the element options of an element.Use the Style.layout() method to retrieve the layout of a widget class.The layout determines how elements assembled the widget. nfigure( 'Error.TLabel', padding=( 10, 10))Īpp.mainloop() Code language: Python ( python ) Summary nfigure( 'Error.TLabel', font=( 'Helvetica', 12)) nfigure( 'Error.TLabel', background= 'red') nfigure( 'Error.TLabel', foreground= 'white') Label = ttk.Label(self, text=message, style= 'Error.TLabel') The following shows how to change the appearance of a Label widget: import tkinter as tk SystemButtonFace Code language: Python ( python )Īs you can see clearly from the output, the font is TkDefaultFont, the foreground is SystemWindowText, and the background is SystemButtonFace. Print(style.lookup( 'Label.label', 'background')) Print(style.lookup( 'Label.label', 'foreground')) Print(style.lookup( 'Label.label', 'font')) ![]() # attributes of the font, foreground, and background # of the Label.label element The following example shows the attributes of the font, foreground, and background options in the TLabel.label element: import tkinter as tk ![]() To get a list of attributes associated with an element option, you use the lookup() method of the Style object: style.lookup(layout_name, option_name) Code language: Python ( python ) The Label.label element has many options including 'font', 'foreground', 'with', etc.The Label.padding element has three options: 'padding', 'relief', and 'shiftrelief'.The Label.border element has one option: 'relief'.( 'compound', 'space', 'text', 'font', 'foreground', 'underline', 'width', 'anchor', 'justify', 'wraplength', 'embossed', 'image', 'stipple', 'background') Code language: Python ( python ) Print(style.element_options( 'Label.label')) Print(style.element_options( 'Label.padding')) Print(style.element_options( 'Label.border')) The following program shows the element options of the Label.border, Label.padding, and Label.label elements: import tkinter as tk To get the list of option names, you use the element_options() method of Style object: style.element_options(styleName) Code language: Python ( python ) Element optionsĮach element has a list of options that specify the appearance of the element. If you change the theme, the layout may be different. ![]() Note that the style’s layout of a widget’s class depends on the current theme. The Label.label is the innermost element that has only one sticky key.įor example, when an element has a sticky key with the value of nswe, it would be stretched to adhere to the north, south, west, and east of the parent element.It also has the sticky, border, and children keys. The Label.padding is nested inside the Label.border.The Label.border is the outermost element that has the sticky, border, and children keys.The TLabel has three elements nested within each other: The following output shows the style’s layout of the TLabel: [( 'Label.border', The following example uses the layout() method to get the layout of the TLabel widget class: import tkinter as tkĪpp.mainloop() Code language: Python ( python ) description is a dictionary that describes the element.element_name is the name of the element.The layout() method returns a list of tuples ( element_name, description), where: If a widget class doesn’t have a layout, the layout() method will raise a tk.TclError exception. To get the layout of a widget class, you use the layout() method of the Style object like this: style.layout(widget_class) Code language: Python ( python ) In general, most of the built-in ttk styles use the concept of a layout to organize the different element layers that build up a widget.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |