How to use the guizero.utilities function in guizero

To help you get started, we’ve selected a few guizero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lawsie / guizero / guizero / ButtonGroup.py View on Github external
Setting to `None` stops the callback.

        :param callback command:
            The callback function to call.

        :param callback args:
            A list of arguments to pass to the widgets `command`, defaults to
            `None`.
        """
        if command is None:
            self._command = lambda: None
        else:
            if args is None:
                self._command = command
            else:
                self._command = utils.with_args(command, *args)
github lawsie / guizero / guizero / MenuBar.py View on Github external
def __init__(self, master, toplevel, options):

        if not isinstance(master, (App, Window)):
            utils.error_format("The [MenuBar] must have an [App] or [Window] object as its master")

        description = "[MenuBar] object "

        # Create a tk Menu object within this object
        tk = Menu(master.tk)

        super(MenuBar, self).__init__(master, tk, description, False)

        # Keep track of submenu objects
        self._sub_menus = []

        # Create all the top level menus
        for i in range(len(toplevel)):
            # Create this submenu
            new_menu = Menu(self.tk, tearoff=0)
github lawsie / guizero / guizero / base.py View on Github external
def _grid_widget(self, widget):
        # If they failed to specify grid coords
        if widget.grid is None:
            utils.error_format("{} will not be displayed because it has a missing grid reference.".format(widget.description))
        elif type(widget.grid) is not list:
            utils.error_format("{} will not be displayed because the grid reference is not a list.".format(widget.description))
        # Can have 2 values (just coords) or 4 values (coords and col/rowspan)
        elif (len(widget.grid) != 2 and len(widget.grid) != 4):
            utils.error_format("{} will not be displayed because the grid reference should be either grid=[x, y] or grid=[x, y, columnspan, rowspan].".format(widget.description))
        else:
            grid_params = {
                "column": widget.grid[0],
                "row": widget.grid[1]
            }

            # Just check we have more than 2 as we have already checked it's a multiple of two previously
            if len(widget.grid) > 2:
                grid_params["columnspan"] = widget.grid[2]
                grid_params["rowspan"] = widget.grid[3]
github lawsie / guizero / guizero / CheckBox.py View on Github external
def value(self, value):
        try:
            value = int(value)
            if value in [0, 1]:
                self._value.set(value)

        except ValueError:
            utils.error_format("You can only set the value of " + self.description + " to either 0 (not checked) or 1 (checked)")
github lawsie / guizero / guizero / event.py View on Github external
def _event_callback(self, tk_event):
        # the tk event has fired, run all the callbacks associated to this event
        for ref in self._callbacks.copy():
            callback = self._callbacks[ref]
            args_expected = utils.no_args_expected(callback)

            if args_expected == 0:
                callback()
            elif args_expected == 1:
                callback(EventData(self._widget, tk_event))
            else:
                utils.error_format("An event callback function must accept either 0 or 1 arguments.\nThe current callback has {} arguments.".format(args_expected))
github lawsie / guizero / guizero / Drawing.py View on Github external
:param str color:
            The color of the shape. Defaults to `"black"`.

        :param int outline:
            `0` or `False` is no outline. `True` or value > 1 sets an outline. Defaults to `False`.

        :param str outline_color:
            The color of the outline. Defaults to `"black"`.

        :return:
            The id of the shape.
        """
        return self.tk.create_polygon(
            *coords, 
            outline = utils.convert_color(outline_color) if outline else "",
            width = int(outline),
            fill = "" if color is None else utils.convert_color(color)
            )
github lawsie / guizero / guizero / base.py View on Github external
def on_close(self, command):
        # deprecated on 2019-06-08
        self.when_closed = command
        utils.deprecated("on_close() is deprecated. Please use the when_closed property instead.")
github lawsie / guizero / guizero / tkmixins.py View on Github external
Validates a Widgets grid property and stores it as a TriggeredList
        which will call the masters display_widgets method when it is changed
        """
        self._grid = None
        if self.master.layout == "grid":
            # validate the grid
            if grid is None:
                utils.error_format("{} will not be displayed because it has a missing grid reference.".format(self.description))
            elif not isinstance(grid, (list, tuple)):
                utils.error_format("{} will not be displayed because the grid reference is not a list or tuple.".format(self.description))
            # Can have 2 values (just coords) or 4 values (coords and col/rowspan)
            elif (len(grid) != 2 and len(grid) != 4):
                utils.error_format("{} will not be displayed because the grid reference should be either grid=[x, y] or grid=[x, y, columnspan, rowspan].".format(self.description))
            else:
                # convert the grid to a trackable list
                self._grid = utils.TriggeredList(grid, on_change=self.master.display_widgets)
        else:
            if grid is not None:
                utils.error_format("A grid is not required for {} as it is not using a 'grid' layout.".format(self.description))