Skip to content

Textbox

A Textbox is a multi-line text input field that allows the user to enter and edit text. Use a Textbox when you want to allow the user to enter more than one line of text, or when you want to display a large amount of text that may not fit in a single line.

Examples

License Viewer

This example loads a text file and creates a Textbox to display its contents.

license_viewer.py
import gooeypie as gp
app = gp.GooeyPieApp("License Viewer")
app.width = 300
# Read the license file
with open("license.txt", "r") as f:
license_text = f.read()
# Display the license text in a textbox and make a button
license_txt = gp.Textbox(license_text)
# Make a button to close the window
close_btn = gp.Button("I accept the terms and conditions", None)
# Add widgets to window
app.add(license_txt, 1, 1, expand_horizontal=True)
app.add(close_btn, 1, 2)
app.run()

Encoder

In this app, the on_change event of one Textbox is used to update the text of another Textbox with an encoded version of the input text.

oncodor.py
import gooeypie as gp
app = gp.GooeyPieApp("The Oncodor")
app.width = 300
def oncodo(event):
"""Oncodo the message text by replacing all vowels with 'o'."""
message = message_textbox.text.lower()
oncodo_text = message.replace("a", "o").replace("e", "o").replace("i", "o").replace("u", "o")
oncodod_textbox.text = oncodo_text
def copy_to_clipboard(event):
"""Copies the oncodod text to the clipboard."""
app.copy_to_clipboard(oncodod_textbox.text)
# Create labels and textboxes
message_label = gp.Label("Message")
message_textbox = gp.Textbox()
message_textbox.height = 100
oncodor_label = gp.Label("Oncodor Text")
oncodod_textbox = gp.Textbox()
oncodod_textbox.height = 100
# Create copy button
copy_button = gp.Button("Copy oncodod text to clipboard", copy_to_clipboard)
# Add event handler to update the oncodod text when the message text changes
message_textbox.on_change(oncodo)
# Add widgets to window
app.add(message_label, 1, 1, align_vertical='top', align_horizontal='right')
app.add(message_textbox, 2, 1)
app.add(oncodor_label, 1, 2, align_vertical='top', align_horizontal='right')
app.add(oncodod_textbox, 2, 2)
app.add(copy_button, 2, 3)
app.run()

Creating a Textbox widget

my_textbox = gp.Textbox(text)

Parameters

  • text (string): Optional. The initial text to display in the textbox.

Properties

Name Type Description
.text string Gets or sets the text of the textbox.
.height integer Gets or sets the height of the textbox in pixels.
.width integer Gets or sets the width of the textbox in pixels.
.disabled boolean Gets or sets whether the textbox is disabled. When disabled is set to True, the textbox does not respond to user input.

Methods

Name Returns Description
.append(text) None Appends the specified text to the existing text in the textbox.
.append_line(text) None Appends the specified text to the existing text in the textbox on a new line.
.prepend(text) None Prepends the specified text to the existing text in the textbox.
.prepend_line(text) None Prepends the specified text to the existing text in the textbox on a new line.
.scroll_to_start() None Scrolls the Textbox so that the start of the text is visible.
.scroll_to_end() None Scrolls the Textbox so that the end of the text is visible.
.focus() None Sets the focus to the textbox, allowing the user to start typing in it immediately.
.clear() None Clears the text in the textbox.

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 textbox changes. This event is triggered whenever the user types in the textbox 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 Textbox.
.style.border_color The color of the border of the Textbox.
.style.border_width The width of the border of the Textbox.
.style.corner_radius The radius of the corners of the Textbox. 6
.style.font_name The font of the text of the Textbox. 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 Textbox. 12
.style.font_weight The weight of the text of the Textbox. Either "normal" or "bold". "normal"
.style.font_style The style of the text of the Textbox. Either "normal" or "italic". "normal"
.style.text_color The color of the text of the Textbox.
.style.text_disabled_color The color of the text of the Textbox when it is disabled.