Skip to content

Secret

A Secret widget is a type of entry widget that is designed for entering sensitive information, such as passwords. By default, the text entered into a Secret widget is masked, meaning that it is displayed as dots (•) instead of the actual characters.

Examples

Login form

Here’s an example of a simple login form with username and password fields. The .text property is used to get the text in both the regulary Entry and the Secret widgets.

login_form.py
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 button
user_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 status
status_label = gp.Label('')
# Add all widgets to the app
app.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()

Tell me a secret

In this example, the toggle() method of the Secret widget is used to show or hide the message.

my_secret.py
import gooeypie as gp
def toggle_secret(event):
secret_entry.toggle()
app = gp.GooeyPieApp('Secret')
app.width = 300
# Create widgets
question_lbl = gp.Label("What's your secret?")
question_lbl.style.font_size = 16
secret_entry = gp.Secret()
secret_chk = gp.Checkbox("Show secret")
# Set event listener for checkbox to show or hide the secret
secret_chk.on_change(toggle_secret)
# Add widgets to window
app.add(question_lbl, 1, 1)
app.add(secret_entry, 1, 2, expand_horizontal=True)
app.add(secret_chk, 1, 3)
app.run()

Creating a Secret widget

my_secret = gp.Secret(placeholder_text)

Parameters

  • placeholder_text (string): Optional. The text that will be displayed in the Secret when it is empty. This text disappears when the Secret gains focus.

Properties

Name Type Description
.text string Gets or sets the text of the secret, even if it is currently masked. When setting this property, the text will be masked or unmasked based on the current state of the secret.
.placeholder_text string Gets or sets the placeholder text of the entry.
.masked boolean Gets whether the text in the secret is currently masked (displayed as dots) or unmasked (displayed as actual characters). This property is read-only; to change the masked state, use the mask(), unmask(), or toggle() methods.
.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
.unmask() None Unmasks the text in the secret, showing the actual characters instead of dots (•).
.mask() None Masks the text in the secret, replacing each character with a dot (•). This is the default behavior of the Secret widget.
.toggle() None Toggles between masked and unmasked states of the secret.
.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

Styles for this widget

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.