This document presents two example Python programs that you can download, install, and run. The first generates a window that contains ttk widgets without styles. The second generates ttk widgets with styles.
Note: Before you can download and run the example code in this document, you need to download and install Python 3 and IDLE for Python 3. IDLE is the Python integrated development environment (IDE). For details, see Getting Started with Python Programming.
Running example ttk widgets without styles
To download and run the Python code for example ttk widgets that have no styles, do the following:
- In a new browser window or tab, go to Ttk_Widgets_Without_Styles.
- Select the entire program, and then press Ctrl+C to copy the code.
- Start Python 3 and open a new window in IDLE.
- Click File, click New File, and then press Ctrl+V to paste your copied code into your new file.
- Save your new file with an appropriate file name, such as ttkWidgetsNoStyles.py.
- Click Run Module to verify that the code generates a Ttk Widgets Without Styles window similar to that in Figure 1.
- Test the window by experimenting with its buttons and its numeric-value entry field.
Figure 1 - Example ttk widgets to which styles have not been applied. |
Running example ttk widgets with styles
To download and run Python code for example ttk widgets that have styles, do the following:- In a new browser window or tab, go to Ttk_Widgets_With_Styles.
- Select the entire program, and then press Ctrl+C to copy the code.
- Start Python 3 and open a new window in IDLE.
- Click File, click New File, and then press Ctrl+V to paste your copied code into your new file.
- Save your new file with an appropriate file name, such as ttkWidgetsWithStyles.py.
- Click Run Module to verify that the code generates a Ttk Widgets With Styles window similar to that in Figure 2.
- Test the window by experimenting with its buttons and its numeric-value entry field.
Figure 2 - Example ttk widgets to which styles have been applied. |
To help you get started with ttk styles, the two subsections below let you compare example Python code fragments that generate ttk widgets without styles and with styles.
Note: Figures 3 and 4 show example Python code fragments as copied into word-processor text.
Generating ttk widgets without styles - The code fragment in Figure 3 generates ttk widgets for labels and buttons shown in Figure 1. This code does not define or apply styles to these widgets.
Figure 3 - Example code fragment that defines ttk widgets without styles. |
Note: You can define a default widget color as a literal string in double quotes, such as "red." You can define a custom color as a hexadecimal string in single quotes, such as '#afd' in the Exit.Tbutton style. You can define a widget border relief as a literal string in double quotes, such as "solid," "flat", "raised", "sunken", "groove" or "ridge."
Figure 4 - Example code fragment that defines ttk widgets with styles. The highlighted code defines the styles. |
No comments :
Post a Comment