Entry
An Entry widget is a single-line text input field that allows the user to enter and edit text. It can be used for various purposes, such as accepting user input, displaying information, or creating forms.
Examples
Hello, you!
In this example, the user enters their name and we say a personalised hello! If they don’t want to tell us their name, we can just say “Hello, friend!” instead.
import gooeypie as gp
def update_greeting(event): """Updates the greeting message based on the user's name.""" if name_entry.text: greeting_lbl.text = f"Hello, {name_entry.text}!" else: greeting_lbl.text = "Hello, friend!"
app = gp.GooeyPieApp("Hello, You!")
# Create widgetsquestion_lbl = gp.Label("What's your name?")name_entry = gp.Entry()say_hello_btn = gp.Button("Say Hello", update_greeting)greeting_lbl = gp.Label()
# Make the label widget widername_entry.width = 200
# Add widgets to the windowapp.add(question_lbl, 1, 1)app.add(name_entry, 1, 2)app.add(say_hello_btn, 1, 3)app.add(greeting_lbl, 1, 4)
app.run()Login form
Here’s an example of a simple login form with username and password fields. When the user clicks the “Login” button, we check if the username and password are correct and display a message accordingly.
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 an Entry widget
my_entry = gp.Entry(placeholder_text)Parameters
-
placeholder_text(string): Optional. The text that will be displayed in the Entry when it is empty. This text disappears when the Entry gains focus.
Properties
| Name | Type | Description |
|---|---|---|
.text | string | Gets or sets the text of the entry. |
.placeholder_text | string | Gets or sets the placeholder text of the entry. |
.width | integer | Gets or sets the width of the entry in pixels. |
.height | integer | Gets or sets the height of the entry in pixels. |
.disabled | boolean | Gets or sets whether the entry is disabled. When disabled is set to True, the entry does not respond to user input. |
Methods
| Name | Returns | Description |
|---|---|---|
.clear() | None | Clears the text in the entry. |
.focus() | None | Sets the focus to the entry, allowing the user to start typing in it immediately. |
.select() | None | Selects all the text in the entry. |
Events
This widget supports the following events as well as the standard events listed below.
| Name | Description |
|---|---|
.on_change(event_function) | The function to call when the text in the entry changes. This event is triggered whenever the user types in the entry or when the text is changed programmatically. |
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.on_key_press.on_focus_gained.on_focus_lost
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.bg_color | The background color of the entry. | |
.style.border_color | The color of the border of the entry. | |
.style.border_width | The width of the border of the entry. | |
.style.corner_radius | The radius of the corners of the entry. | 6 |
.style.font_name | The font of the text of the Entry. 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 Entry. | 12 |
.style.font_weight | The weight of the text of the Entry. Either "normal" or "bold". | "normal" |
.style.font_style | The style of the text of the Entry. Either "normal" or "italic". | "normal" |
.style.justify | The horizontal alignment of the text in the entry. Can be set to "left", "center", or "right". | "left" |
.style.text_color | The color of the text of the entry. | |
.style.text_disabled_color | The color of the text of the entry when it is disabled. | |
.style.placeholder_color | The color of the placeholder text of the entry. |