示例#1
0
    def __init__(self,
                 rect: pygame.Rect,
                 on_value_changed: Callable[[str], None] = None,
                 on_edit_finished: Callable[[str], None] = None,
                 text: str = "",
                 character_limit: int = 14,
                 style: Style = None,
                 parent: Component = None) -> None:
        """Create a new Textbox. <rect> is the rectangle representing this
        component's position and size on the screen. <on_value_changed> is the
        function called when the textbox's text is changed. <on_edit_finished>
        is the function called when the textbox's text is done being changed.
        <text> is the starting text of the textbox. <character_limit> is the
        maximum number of characters that the textbox can have. <style>
        dictates the appearence of the component. If None, the default style
        will be used. <parent> is the component that is immediately above this
        component in the tree.
        """
        Label.__init__(self, rect, text=text, style=style, parent=parent)

        self._on_value_changed = on_value_changed
        self._on_edit_finished = on_edit_finished
        self._time_since_blink = 0
        self._time_for_blink = 500
        self._is_blinker_on = False
        self._cursor_pos = 0
        self._selection_end_pos = 0
        self._is_selection_finished = True
        self._character_limit = character_limit
示例#2
0
    def __init__(self,
                 rect: Rect,
                 on_click: Callable[[int], None] = None,
                 text: str = "",
                 style: Style = None,
                 parent: Component = None) -> None:
        """Create a new Button. <rect> is the rectangle representing this
        component's position and size on the screen. <on_click> is the
        function called when the button is clicked. <text> is the text to be
        displayed. <style> dictates the appearence of the component. If None,
        the default style will be used. <parent> is the component that is
        immediately above this component in the tree.
        """
        Label.__init__(self, rect, text=text, style=style, parent=parent)

        if (on_click is not None):
            self._on_click = on_click