Label
A Label widget displays text in the app. The text of the label can be set when creating the Label widget, or by setting the text property of the Label widget after it has been created.
Examples
Login form
Here’s an example of a simple login form with username and password fields. Static Labels are used to indicate which field is for the username and which is for the password, and a Label that starts off empty is used to display a message when the user clicks the login button.
import gooeypie as gp
def check_login(event): """Checks the username and password and updates the status label.""" if user_entry.text == 'admin' and pass_entry.text == 'bestpassword': status_label.text = '✔ Access granted!' else: status_label.text = '❌ Access denied!'
app = gp.GooeyPieApp('Login')
# Create labels and Entry widgets and a login buttonuser_label = gp.Label("Username")user_entry = gp.Entry()pass_label = gp.Label("Password")pass_entry = gp.Secret()login_btn = gp.Button('Login', check_login)
# An initially empty label to display the login statusstatus_label = gp.Label('')
# Add all widgets to the appapp.add(user_label, 1, 1)app.add(user_entry, 2, 1)app.add(pass_label, 1, 2)app.add(pass_entry, 2, 2)app.add(login_btn, 2, 3)app.add(status_label, 2, 4)
app.run()Creating a Label widget
my_label = gp.Label(label_text)Parameters
-
label_text(string): The text of the label.
Properties
| Name | Type | Description |
|---|---|---|
.text | string | Gets or sets the text of the label. |
.width | integer | Gets or sets the width of the label in pixels. |
.height | integer | Gets or sets the height of the label in pixels. |
.disabled | boolean | Gets or sets whether the label is disabled. A label should be disabled to visually signal that any associated widgets, like an Entry, are inactive. |
Methods
This widget has no unique methods.
Events
This widget has no unique events. It supports the standard events listed below.
Standard events
.on_click.on_double_click.on_right_click.on_middle_click.on_mouse_down.on_mouse_up.on_mouse_enter.on_mouse_leave
Styles
How to specify colors
- Colors can be specified as either a hex code (e.g.
"#FF0000"), a CSS color name, or"transparent". - When specifying a color for a style, you can provide either a single color or two colors separated by a comma. If you provide two colors, the first will be used for light mode and the second for dark mode. For example,
my_widget.text_color = "steelblue", "skyblue"would specify steelblue for light mode and sky blue for dark mode.
| Name | Description | Default |
|---|---|---|
.style.align | The alignment of the label within its cell. Either "left", "center" or "right". | "center" |
.style.bg_color | The background color of the label. Take care not to make a label look like a button by giving it a background color. | "transparent" |
.style.corner_radius | The radius of the corners of the label. | 6 |
.style.justify | The justification of the text of the label if it spans over multiple lines. Either "left", "center" or "right". | "center" |
.style.padding | Additional space around the text of the label | 0 |
.style.text_color | The color of the text of the label. | |
.style.text_disabled_color | The color of the text of the label when it is disabled. | |
.style.font_name | The font of the text of the button. Either an installed font or a generic font name: "serif", "sans-serif", "monospace" or "system" | "system" |
.style.font_size | The size of the text of the button. | 12 |
.style.font_weight | The weight of the text of the button. Either "normal" or "bold". | "normal" |
.style.font_style | The style of the text of the button. Either "normal" or "italic". | "normal" |