TTkLineEdit🌶️

class TTkLineEdit(*, text: str | ~TermTk.TTkCore.string.TTkString = '', hint: str | ~TermTk.TTkCore.string.TTkString = '', inputType: ~TermTk.TTkCore.constant.TTkConstant.InputType = <InputType.Input_Text: 1>, echoMode: ~TermTk.TTkWidgets.lineedit.TTkLineEdit.EchoMode = EchoMode.Normal, **kwargs)[source]🌶️

Bases: TTkWidget

TTkLineEdit:

A single-line text editor widget for user input. (demo)

Standard:  |Hello World________|
Password:  |**********_________|
Number:    |123.45_____________|
import TermTk as ttk

root = ttk.TTk()

# Basic text input
edit = ttk.TTkLineEdit(parent=root, pos=(1,1), size=(20,1), text="Hello")

# Password input
password = ttk.TTkLineEdit(parent=root, pos=(1,2), size=(20,1),
                           echoMode=ttk.TTkLineEdit.EchoMode.Password)

# Numeric input
number = ttk.TTkLineEdit(parent=root, pos=(1,3), size=(20,1),
                        inputType=ttk.TTkK.InputType.Input_Number)

# Connect to signal
edit.textEdited.connect(lambda text: ttk.TTkLog.debug(f"Edited: {text}"))

root.mainloop()
param text:

Initial text content

type text:

TTkString or str, optional

param hint:

Placeholder text shown when empty

type hint:

TTkString or str, optional

param inputType:

Input validation type (TTkK.InputType.Input_Text or TTkK.InputType.Input_Number)

type inputType:

int, optional

param echoMode:

How text is displayed (Normal, NoEcho, Password, PasswordEchoOnEdit)

type echoMode:

EchoMode, optional

TTkWidget’s inherited init params:

Parameters:
  • name (str, optional) – the name of the widget, defaults to “”

  • parent (TTkWidget, optional) – the parent widget, defaults to None

  • x (int, optional) – the x position, defaults to 0

  • y (int, optional) – the y position, defaults to 0

  • pos ((int,int), optional) – the [x,y] position (override the previously defined x, y), defaults to (x,y)

  • width (int, optional) – the width of the widget, defaults to 0

  • height (int, optional) – the height of the widget, defaults to 0

  • size ((int,int), optional) – the size [width, height] of the widget (override the previously defined sizes), defaults to (width,height)

  • maxWidth (int, optional) – the maxWidth of the widget, defaults to 0x10000

  • maxHeight (int, optional) – the maxHeight of the widget, defaults to 0x10000

  • maxSize ((int,int), optional) – the max [width,height] of the widget, optional, defaults to (maxWidth,maxHeight)

  • minWidth (int, optional) – the minWidth of the widget, defaults to 0

  • minHeight (int, optional) – the minHeight of the widget, defaults to 0

  • minSize ((int,int), optional) – the minSize [width,height] of the widget, optional, defaults to (minWidth,minHeight)

  • toolTip (TTkString, optional) – This property holds the widget’s tooltip, defaults to ‘’

  • style (dict, optional) – this field hold the custom style to be used by this widget

  • addStyle (dict, optional) – this field is required to override/merge the new style on top of the current one, useful if only few params need to be changed

  • visible (bool, optional) – the visibility, optional, defaults to True

  • enabled (bool, optional) – the ability to handle input events, optional, defaults to True

TMouseEvents’s inherited init params:

Initialize self. See help(type(self)) for accurate signature.

TDragEvents’s inherited init params:

Initialize self. See help(type(self)) for accurate signature.

Style🌶️

classStyle = {
            'default':     {'color':         TTkColor.fgbg("#dddddd","#222222"),
                            'bgcolor':       TTkColor.fgbg("#666666","#222222")+TTkColor.UNDERLINE,
                            'selectedColor': TTkColor.fgbg("#ffffff","#008844")},
            'disabled':    {'color':         TTkColor.fg(  "#888888"),
                            'bgcolor':       TTkColor.fg(  "#444444")+TTkColor.UNDERLINE,
                            'selectedColor': TTkColor.fgbg("#888888","#444444")},
            'focus':       {'color':         TTkColor.fgbg("#dddddd","#000044"),
                            'bgcolor':       TTkColor.fgbg("#666666","#000044")+TTkColor.UNDERLINE}
        }

Signals🌶️

closed

This signal is emitted whenever the widget is closed

currentStyleChanged

This signal is emitted whenever the widget stye change

focusChanged

This signal is emitted whenever the focus status change i.e. with the setFocus() or clearFocus() methods.

returnPressed

This signal is emitted when the Return or Enter key is pressed.

sizeChanged

This signal is emitted whenever the widget size change

textChanged

This signal is emitted whenever the text changes programmatically or through user input.

textEdited

This signal is emitted whenever the text is edited by the user (not programmatically).

Slots🌶️

copy()

Copy the selected text to the clipboard

cut()

Cut the selected text to the clipboard

paste()

Paste text from the clipboard at the cursor position

setText(text[, cursorPos])

Set the text content of the line edit

Slots Inherited from: TTkWidget

close()

Close (Destroy/Remove) the widget

hide()

hide the widget

lowerWidget()

Lower the Widget below its relatives

raiseWidget([raiseParent])

Raise the Widget above its relatives

setDisabled([disabled])

This property holds whether the widget is disnabled

setEnabled([enabled])

This property holds whether the widget is enabled

setFocus()

Focus the widget

setVisible(visible)

Set the visibility status of this widget

show()

show the widget

update([repaint, updateLayout, updateParent])

Notify the drawing routine that the widget changed and needs to draw its new content.

Members🌶️

closed: pyTTkSignal🌶️

This signal is emitted whenever the widget is closed

Parameters:

widget (TTkWidget) – the widget closed (=self)

currentStyleChanged: pyTTkSignal🌶️

This signal is emitted whenever the widget stye change

Parameters:

style (dict) – the new style applied

focusChanged: pyTTkSignal🌶️

This signal is emitted whenever the focus status change i.e. with the setFocus() or clearFocus() methods

Parameters:

status (bool) – the curent focus status

returnPressed: pyTTkSignal🌶️

This signal is emitted when the Return or Enter key is pressed.

sizeChanged: pyTTkSignal🌶️

This signal is emitted whenever the widget size change

Parameters:
  • width (int) – the new widget width

  • height (int) – the new widget height

textChanged: pyTTkSignal🌶️

This signal is emitted whenever the text changes programmatically or through user input.

Parameters:

text (str) – The new text content

textEdited: pyTTkSignal🌶️

This signal is emitted whenever the text is edited by the user (not programmatically).

Parameters:

text (str) – The edited text content

Methods🌶️

copy()[source]🌶️

Copy the selected text to the clipboard

cut()[source]🌶️

Cut the selected text to the clipboard

echoMode() EchoMode[source]🌶️

Get the current echo mode

Returns:

The current echo mode

Return type:

EchoMode

inputType() InputType[source]🌶️

Get the current input validation type

Returns:

The input type (TTkK.InputType.Input_Text or TTkK.InputType.Input_Number)

Return type:

TTkK.InputType

paste()[source]🌶️

Paste text from the clipboard at the cursor position

setEchoMode(echoMode: EchoMode)[source]🌶️

Set how text is displayed

Parameters:

echoMode (EchoMode) – The echo mode (Normal, NoEcho, Password, PasswordEchoOnEdit)

setInputType(inputType: InputType) None[source]🌶️

Set the input validation type

When set to Input_Number, only numeric values (including decimals) are accepted.

Parameters:

inputType (TTkK.InputType) – The input type to validate against

setText(text: str | TTkString, cursorPos: int = 4096) None[source]🌶️

Set the text content of the line edit

Parameters:
  • text (TTkString or str) – The new text to display

  • cursorPos (int, optional) – Position to place the cursor (defaults to end of text)

text() TTkString[source]🌶️

Get the current text content

Returns:

The current text

Return type:

TTkString

Methods Inherited from: TTkWidget

clearFocus()

Remove the Focus state of this widget

close()

Close (Destroy/Remove) the widget

currentStyle()

disableWidgetCursor([disable])

enableWidgetCursor([enable])

focusInEvent()

focusOutEvent()

focusPolicy()

geometry()

getCanvas()

getPixmap()

Convenience function which return a pixmap representing the current widget status

getWidgetByName(name)

hasFocus()

This property holds the focus status of this widget

height()

hide()

hide the widget

isEnabled()

This property holds whether the widget is enabled

isEntered()

isVisible()

Retrieve the visibility status of this widget

isVisibleAndParent()

lowerWidget()

Lower the Widget below its relatives

maxDimension(orientation)

maximumHeight()

maximumSize()

maximumWidth()

mergeStyle(style)

minDimension(orientation)

minimumHeight()

minimumSize()

minimumWidth()

mouseEvent(evt)

move(x, y)

Move the widget

moveEvent(x, y)

Convenience function, Event Callback triggered after a successful move

name()

paintChildCanvas()

paintEvent(canvas)

Paint Event callback, this need to be overridden in the widget.

parentWidget()

pasteEvent(txt)

Handle paste event with custom text

pos()

raiseWidget([raiseParent])

Raise the Widget above its relatives

resize(width, height)

Resize the widget

resizeEvent(w, h)

Convenience function, Event Callback triggered after a successful resize

setCurrentStyle(style)

setDefaultSize(arg, width, height)

setDisabled([disabled])

This property holds whether the widget is disnabled

setDropEventProxy(proxy)

setEnabled([enabled])

This property holds whether the widget is enabled

setFocus()

Focus the widget

setFocusPolicy(policy)

This property holds the way the widget accepts keyboard focus

setGeometry(x, y, width, height)

Resize and move the widget

setMaximumHeight(maxh)

setMaximumSize(maxw, maxh)

setMaximumWidth(maxw)

setMinimumHeight(minh)

setMinimumSize(minw, minh)

setMinimumWidth(minw)

setName(name)

Set the name of this Instance

setParent(parent)

setStyle([style])

setToolTip(toolTip)

setVisible(visible)

Set the visibility status of this widget

setWidgetCursor([pos, type])

show()

show the widget

size()

style()

toolTip()

update([repaint, updateLayout, updateParent])

Notify the drawing routine that the widget changed and needs to draw its new content.

widgetItem()

width()

x()

y()

Methods Inherited from: TMouseEvents

enterEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse enter events for the widget.

leaveEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse leave events for the widget.

mouseDoubleClickEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse click events for the widget.

mouseDragEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse drag events for the widget.

mouseMoveEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse move events for the widget.

mousePressEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse press events for the widget.

mouseReleaseEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse release events for the widget.

mouseTapEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse click events for the widget.

wheelEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse wheel events for the widget.

Methods Inherited from: TKeyEvents

keyEvent(evt)

This event handler, can be reimplemented in a subclass to receive key events for the widget.

Methods Inherited from: TDragEvents

dragEnterEvent(evt)

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

dragLeaveEvent(evt)

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

dragMoveEvent(evt)

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

dropEvent(evt)

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

TTkLineEdit Classes🌶️

class EchoMode(*values)🌶️

Bases: IntEnum

EchoMode:

Defines how text input is displayed in the line edit.

NoEcho = 1🌶️

Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.

Normal = 0🌶️

Display characters as they are entered. This is the default.

Password = 2🌶️

Display asterisks instead of the characters actually entered.

PasswordEchoOnEdit = 3🌶️

Display characters as they are entered while editing otherwise display asterisks.

TTkLineEdit Attributes🌶️

classStyle