TTkWidget🌢️

class TTkWidget(parent: Self = None, x: int = 0, y: int = 0, width: int = 0, height: int = 0, pos: tuple = None, size: tuple = None, maxSize: tuple = None, maxWidth: int = 65536, maxHeight: int = 65536, minSize: tuple = None, minWidth: int = 0, minHeight: int = 0, name: str = None, visible: bool = True, enabled: bool = True, toolTip: TTkString = '', style: dict = None, addStyle: dict = None, **kwargs)[source]🌢️

Bases: TMouseEvents, TKeyEvents, TDragEvents

Widget sizes:

Terminal area (i.e. XTerm) = TTk
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                         β”‚
β”‚    TTkWidget     width                  β”‚
β”‚ (x,y)β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚      β”‚                         β”‚        β”‚
β”‚      β”‚                         β”‚ height β”‚
β”‚      β”‚                         β”‚        β”‚
β”‚      β”‚                         β”‚        β”‚
β”‚      β”‚                         β”‚        β”‚
β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The TTkWidget class is the base class of all user interface objects

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

Style🌢️

classStyle = {
            'default':     {'color': TTkColor.RST,           'borderColor': TTkColor.RST},
            'disabled':    {'color': TTkColor.fg('#888888'), 'borderColor': TTkColor.fg('#888888')},
            # 'hover':       {'color': TTkColor.fg('#00FF00')+TTkColor.bg('#0077FF')},
            # 'checked':     {'color': TTkColor.fg('#00FF00')+TTkColor.bg('#00FFFF')},
            # 'clicked':     {'color': TTkColor.fg('#FFFF00')},
            # 'focus':       {'color': TTkColor.fg('#FFFF88')},
        }

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.

sizeChanged

This signal is emitted whenever the widget size change

Slots🌢️

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

sizeChanged: pyTTkSignal🌢️

This signal is emitted whenever the widget size change

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

  • height (int) – the new widget height

Methods🌢️

clearFocus() None[source]🌢️

Remove the Focus state of this widget

close() None[source]🌢️

Close (Destroy/Remove) the widget

currentStyle() dict[source]🌢️
disableWidgetCursor(disable: bool = True) None[source]🌢️
enableWidgetCursor(enable: bool = True) None[source]🌢️
focusInEvent() None[source]🌢️
focusOutEvent() None[source]🌢️
focusPolicy() FocusPolicy[source]🌢️
geometry() tuple[int, int, int, int][source]🌢️
getCanvas() TTkCanvas[source]🌢️
getPixmap() TTkCanvas[source]🌢️

Convenience function which return a pixmap representing the current widget status

Returns:

TTkCanvas

getWidgetByName(name: str)[source]🌢️
hasFocus() bool[source]🌢️

This property holds the focus status of this widget

Returns:

bool

height() int[source]🌢️
hide() None[source]🌢️

hide the widget

isEnabled() bool[source]🌢️

This property holds whether the widget is enabled

use setEnabled() or setDisabled() to change this property

Returns:

bool

isEntered() bool[source]🌢️
isVisible() bool[source]🌢️

Retrieve the visibility status of this widget

Returns:

bool

isVisibleAndParent() bool[source]🌢️
lowerWidget() None[source]🌢️

Lower the Widget below its relatives

maxDimension(orientation: Direction) int[source]🌢️
maximumHeight() int[source]🌢️
maximumSize() tuple[int, int][source]🌢️
maximumWidth() int[source]🌢️
mergeStyle(style) None[source]🌢️
minDimension(orientation: Direction) int[source]🌢️
minimumHeight() int[source]🌢️
minimumSize() tuple[int, int][source]🌢️
minimumWidth() int[source]🌢️
mouseEvent(evt: TTkMouseEvent) bool[source]🌢️

Caution

Don Not touch this!

move(x: int, y: int) None[source]🌢️

Move the widget

Parameters:
  • x (int) – the horizontal position

  • y (int) – the vertical position

moveEvent(x: int, y: int) None[source]🌢️

Convenience function, Event Callback triggered after a successful move

Note

Override this method to handle this event

Parameters:
  • x (int) – the new horizontal position

  • y (int) – the new vertical position

name() str[source]🌢️
paintChildCanvas() None[source]🌢️
paintEvent(canvas: TTkCanvas) None[source]🌢️

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

Note

Override this method to handle this event

Parameters:

canvas (TTkCanvas) – the canvas where the content need to be drawn

parentWidget()[source]🌢️
pasteEvent(txt: str) None[source]🌢️

Callback triggered when a paste event is forwarded to this widget.

Note

Reimplement this function to handle this event

Parameters:

txt (str) – the paste object

pos() tuple[int, int][source]🌢️
raiseWidget(raiseParent: bool = True) None[source]🌢️

Raise the Widget above its relatives

resize(width: int, height: int) None[source]🌢️

Resize the widget

Parameters:
  • width (int) – the new width

  • height (int) – the new height

resizeEvent(width: int, height: int) None[source]🌢️

Convenience function, Event Callback triggered after a successful resize

Note

Override this method to handle this event

Parameters:
  • width (int) – the new width

  • height (int) – the new height

setCurrentStyle(style) dict[source]🌢️
setDefaultSize(arg, width: int, height: int) None[source]🌢️
setDisabled(disabled: bool = True) None[source]🌢️

This property holds whether the widget is disnabled

This is a convenience function wrapped around setEnabled() where (not disabled) is used

Parameters:

disabled (bool) – the disabled status, defaults to True

setEnabled(enabled: bool = True) None[source]🌢️

This property holds whether the widget is enabled

In general an enabled widget handles keyboard and mouse events; a disabled widget does not.

Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled.

Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.

By default, this property is true.

Parameters:

enabled (bool) – the enabled status, defaults to True

setFocus() None[source]🌢️

Focus the widget

setFocusPolicy(policy: FocusPolicy) None[source]🌢️

This property holds the way the widget accepts keyboard focus

The policy is TTkK.FocusPolicy.TabFocus if the widget accepts keyboard focus by tabbing, TTkK.FocusPolicy.ClickFocus if the widget accepts focus by clicking, TTkK.FocusPolicy.StrongFocus if it accepts both, and TTkK.FocusPolicy.NoFocus (the default) if it does not accept focus at all.

You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget’s constructor. For instance, the TTkLineEdit constructor calls setFocusPolicy() with TTkK.FocusPolicy.StrongFocus.

If the widget has a focus proxy, then the focus policy will be propagated to it.

Parameters:

policy (TTkK.FocusPolicy) – the focus policy

setGeometry(x: int, y: int, width: int, height: int)[source]🌢️

Resize and move the widget

Parameters:
  • x (int) – the horizontal position

  • y (int) – the vertical position

  • width (int) – the new width

  • height (int) – the new height

setMaximumHeight(maxh: int)[source]🌢️
setMaximumSize(maxw: int, maxh: int)[source]🌢️
setMaximumWidth(maxw: int)[source]🌢️
setMinimumHeight(minh: int)[source]🌢️
setMinimumSize(minw: int, minh: int)[source]🌢️
setMinimumWidth(minw: int)[source]🌢️
setName(name: str) None[source]🌢️

Set the name of this Instance

Parameters:

name (str) – the name to be set

setParent(parent) None[source]🌢️
setStyle(style=None) None[source]🌢️
setToolTip(toolTip: TTkString) None[source]🌢️
setVisible(visible: bool) None[source]🌢️

Set the visibility status of this widget

Parameters:

visible (bool:) – status

setWidgetCursor(pos=None, type=None) None[source]🌢️
show() None[source]🌢️

show the widget

size() tuple[int, int][source]🌢️
style() dict[source]🌢️
toolTip() TTkString[source]🌢️
update(repaint: bool = True, updateLayout: bool = False, updateParent: bool = False) None[source]🌢️

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

It is important to call this method anytime a canvas update is required after a a status update.

Once update() is called, the paintEvent() is executed during the next screen refresh.

i.e.

class NewLabel(TTkWidget):
    def __init__(self,**kwargs) -> None:
        self.text = ""
        super().__init__(**kwargs)

    def setText(self, text:str) -> None:
        self.text = text
        # Notify the runtime that un update
        # is required will trigger the paintEvent
        # at the next screen (terminal) refresh
        self.update()

    def paintEvent(self, canvas:TTkCanvas) -> None:
        canvas.drawText(pos=(0,0), text=self.text)
widgetItem() TTkWidgetItem[source]🌢️
width() int[source]🌢️
x() int[source]🌢️
y() int[source]🌢️

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.

TTkWidget Attributes🌢️

classStyle