From c70eb4f174b74e5e02bbd69898803b677ae5512b Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Sat, 31 Oct 2020 11:54:50 +0000 Subject: [PATCH 01/12] Correct calculation for size of canvas to account for padding. Correct calculations of offsets into canvas on a click event to account for padding --- guizero/Waffle.py | 70 +++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/guizero/Waffle.py b/guizero/Waffle.py index 059282bc..fe938854 100644 --- a/guizero/Waffle.py +++ b/guizero/Waffle.py @@ -6,19 +6,19 @@ class Waffle(Widget): def __init__( - self, - master, - height=3, - width=3, - dim=20, - pad=5, - color="white", - dotty=False, - grid=None, - align=None, - command=None, - visible=True, - enabled=None, + self, + master, + height=3, + width=3, + dim=20, + pad=5, + color="white", + dotty=False, + grid=None, + align=None, + command=None, + visible=True, + enabled=None, bg=None): description = "[Waffle] object ({}x{})".format(height, width) @@ -56,7 +56,7 @@ def __init__( def _create_waffle(self): if self._height == "fill" or self._width == "fill": utils.raise_error("{}\nCannot use 'fill' for width and height.".format(self.description)) - + self._create_canvas() self._size_waffle() self._draw_waffle() @@ -67,9 +67,14 @@ def _create_canvas(self): self._canvas.delete("all") self._canvas.destroy() - #size the canvas - self._c_height = (self._height * (self._pixel_size + self._pad)) + (self._pad * 2) - self._c_width = self._width * (self._pixel_size + self._pad) + (self._pad * 2) + # size the canvas. Each element of the waffle has padding to top, + # bottom, left and right, but the padding is shared between elements. + # What this means in pratice is that elements at the edge have a whole + # padding width between them and the edge of the canvas and a single + # padding width between individual elements, so the padding between + # elements is shared. + self._c_height = (self._height * (self._pixel_size + self._pad)) + self._pad + self._c_width = (self._width * (self._pixel_size + self._pad)) + self._pad # create the canvas and pack it into the waffle frame self._canvas = Canvas(self.tk, height=self._c_height, width=self._c_width, bd=0, highlightthickness=0) @@ -161,18 +166,25 @@ def _clicked_on(self,e): # you can only click on the waffle if its enabled if self._enabled: canvas = e.tk_event.widget - x = canvas.canvasx(e.tk_event.x) - y = canvas.canvasy(e.tk_event.y) - pixel_x = int(x / (self._pixel_size + self._pad)) - pixel_y = int(y / (self._pixel_size + self._pad)) - if self._command: - args_expected = utils.no_args_expected(self._command) - if args_expected == 0: - self._command() - elif args_expected == 2: - self._command(pixel_x,pixel_y) - else: - utils.error_format("Waffle command function must accept either 0 or 2 arguments.\nThe current command has {} arguments.".format(args_expected)) + # Because the padding between waffle elements is shared we have to + # determine which element is being clicked on if the user clicks on + # the padding between elements and on the padding around the + # elements at the edge of the waffle. The approach taken is that + # half of the padding belongs to each element and padding at the + # edges of the canvas are excluded + x = int(canvas.canvasx(e.tk_event.x) - (self._pad / 2)) + y = int(canvas.canvasy(e.tk_event.y) - (self._pad / 2)) + if x >= 0 and y >= 0: + pixel_x = int(x / (self._pixel_size + self._pad)) + pixel_y = int(y / (self._pixel_size + self._pad)) + if self._command and pixel_x < self._width and pixel_y < self._height: + args_expected = utils.no_args_expected(self._command) + if args_expected == 0: + self._command() + elif args_expected == 2: + self._command(pixel_x,pixel_y) + else: + utils.error_format("Waffle command function must accept either 0 or 2 arguments.\nThe current command has {} arguments.".format(args_expected)) def update_command(self, command): if command is None: From 3f4b70148d01005726b43ee15c62a336ea62fd07 Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Thu, 19 Nov 2020 08:40:45 +0000 Subject: [PATCH 02/12] refactored description --- guizero/App.py | 3 --- guizero/Box.py | 5 +---- guizero/ButtonGroup.py | 11 ++++++++--- guizero/CheckBox.py | 12 ++++++++---- guizero/Combo.py | 13 ++++++++----- guizero/Drawing.py | 4 +--- guizero/ListBox.py | 7 ++----- guizero/MenuBar.py | 4 +--- guizero/Picture.py | 4 +--- guizero/PushButton.py | 14 ++++++++------ guizero/RadioButton.py | 12 ++++++++---- guizero/Slider.py | 11 +++++++++-- guizero/Text.py | 12 +++++++----- guizero/TextBox.py | 12 ++++++++---- guizero/Waffle.py | 11 ++++++++--- guizero/Window.py | 3 --- guizero/base.py | 43 ++++++++++++++++++++---------------------- 17 files changed, 98 insertions(+), 83 deletions(-) diff --git a/guizero/App.py b/guizero/App.py index 3f2b5882..1cd6ecbb 100644 --- a/guizero/App.py +++ b/guizero/App.py @@ -43,8 +43,6 @@ def __init__( """ - description = "[App] object" - # If this is the first app to be created, create Tk if App._main_app is None: tk = Tk() @@ -59,7 +57,6 @@ def __init__( super(App, self).__init__( None, tk, - description, title, width, height, diff --git a/guizero/Box.py b/guizero/Box.py index 890f2da2..d7cdb451 100644 --- a/guizero/Box.py +++ b/guizero/Box.py @@ -54,12 +54,9 @@ def __init__( Sets the border thickness. `0` or `False` is no border. `True` or value > 1 sets a border. The default is `None`. """ - - description = "[Box] object (may also contain other objects)" - tk = Frame(master.tk) - super(Box, self).__init__(master, tk, description, layout, grid, align, visible, enabled, width, height) + super(Box, self).__init__(master, tk, layout, grid, align, visible, enabled, width, height) self.resize(width, height) diff --git a/guizero/ButtonGroup.py b/guizero/ButtonGroup.py index 91b3e665..6423da15 100644 --- a/guizero/ButtonGroup.py +++ b/guizero/ButtonGroup.py @@ -70,8 +70,6 @@ def __init__( size. """ - description = "[ButtonGroup] object with selected option \"" + str(selected) + "\"" - self._rbuttons = [] # List of RadioButton objects self._text_size = None self._font = None @@ -84,7 +82,7 @@ def __init__( self._selected = StringVar(master=tk.winfo_toplevel()) # ButtonGroup uses "grid" internally to sort the RadioButtons - super(ButtonGroup, self).__init__(master, tk, description, "grid", grid, align, visible, enabled, width, height) + super(ButtonGroup, self).__init__(master, tk, "grid", grid, align, visible, enabled, width, height) # Loop through the list given and setup the options self._options = [] @@ -229,6 +227,13 @@ def options(self): """ return self._options + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[ButtonGroup] object with selected option '{}'".format(self.value) + # METHODS # ----------------------------------- diff --git a/guizero/CheckBox.py b/guizero/CheckBox.py index 80059d5e..d660b555 100644 --- a/guizero/CheckBox.py +++ b/guizero/CheckBox.py @@ -55,13 +55,11 @@ def __init__( size. """ - description = "[CheckBox] object with text \"" + text + "\"" - self._text = str(text) self._value = IntVar() tk = Checkbutton(master.tk, text=text, variable=self._value) - super(CheckBox, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(CheckBox, self).__init__(master, tk, grid, align, visible, enabled, width, height) # Set the command callback self.tk.config(command=self._command_callback) @@ -101,7 +99,13 @@ def text(self): def text(self, text): self._text = str(text) self.tk.config(text=self._text) - self.description = "[CheckBox] object with text \"" + str(self._text) + "\"" + + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[CheckBox] object with text '{}'".format(self.text) # METHODS # ------------------------------------------- diff --git a/guizero/Combo.py b/guizero/Combo.py index 826d81fc..62a87a15 100644 --- a/guizero/Combo.py +++ b/guizero/Combo.py @@ -70,8 +70,6 @@ def __init__( # Maintain a list of options (as strings, to avoid problems comparing) self._options = [str(x) for x in options] - description = "[Combo] object with options " + str(self._options) - # Store currently selected item self._selected = StringVar() @@ -84,7 +82,7 @@ def __init__( # Create the combo menu object self._combo_menu = ComboMenu(tk["menu"]) - super(Combo, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(Combo, self).__init__(master, tk, grid, align, visible, enabled, width, height) # Remove the thick highlight when the bg is a different color self._set_tk_config("highlightthickness", 0) @@ -172,6 +170,13 @@ def options(self): """ return self._options + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[Combo] object with options {}".format(self._options) + # METHODS # ------------------------------------------- @@ -263,8 +268,6 @@ def _refresh_options(self): for item in self._options: self._combo_menu.tk.add_command(label=item, command=_setit(self._selected, item, self._command_callback)) - self.description = "[Combo] object with options " + str(self._options) - # set the option which was previously selected self._set_option(selected) diff --git a/guizero/Drawing.py b/guizero/Drawing.py index ecd90db2..0ba940a0 100644 --- a/guizero/Drawing.py +++ b/guizero/Drawing.py @@ -48,11 +48,9 @@ def __init__( # list to hold references to images, otherwise tk destroys them self._images = {} - description = "[Drawing] object" - tk = Canvas(master.tk, height=100, width=100, bd=0, highlightthickness=0) - super(Drawing, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(Drawing, self).__init__(master, tk, grid, align, visible, enabled, width, height) def line(self, x1, y1, x2, y2, color="black", width=1): """ diff --git a/guizero/ListBox.py b/guizero/ListBox.py index cff78fd0..3a434b96 100644 --- a/guizero/ListBox.py +++ b/guizero/ListBox.py @@ -66,11 +66,9 @@ def __init__( size. """ - description = "[ListBox] object" - tk = Frame(master.tk) - super(ListBox, self).__init__(master, tk, description, "auto", grid, align, visible, enabled, width, height) + super(ListBox, self).__init__(master, tk, "auto", grid, align, visible, enabled, width, height) self._listbox = ListBoxWidget(self, items, selected, command, None, "left", visible, enabled, multiselect, None, None) self._listbox.resize("fill", "fill") @@ -173,7 +171,6 @@ class ListBoxWidget(TextWidget): def __init__(self, master, items=None, selected=None, command=None, grid=None, align=None, visible=True, enabled=None, multiselect=False, width=None, height=None): - description = "[ListBox] object" self._multiselect = multiselect # Create a tk OptionMenu object within this object @@ -186,7 +183,7 @@ def __init__(self, master, items=None, selected=None, command=None, grid=None, a for item in items: tk.insert(END, item) - super(ListBoxWidget, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(ListBoxWidget, self).__init__(master, tk, grid, align, visible, enabled, width, height) self.events.set_event("", "<>", self._command_callback) diff --git a/guizero/MenuBar.py b/guizero/MenuBar.py index 9fc10928..336840a7 100644 --- a/guizero/MenuBar.py +++ b/guizero/MenuBar.py @@ -35,12 +35,10 @@ 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) + super(MenuBar, self).__init__(master, tk, False) # Keep track of submenu objects self._sub_menus = [] diff --git a/guizero/Picture.py b/guizero/Picture.py index f5952cb9..200cafb8 100644 --- a/guizero/Picture.py +++ b/guizero/Picture.py @@ -47,8 +47,6 @@ def __init__( size. """ - description = "[Picture] object" - self._image_source = image self._image = None self._image_player = None @@ -56,7 +54,7 @@ def __init__( # Instantiate label object which will contain image tk = Label(master.tk) - super(Picture, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(Picture, self).__init__(master, tk, grid, align, visible, enabled, width, height) # create the image self._load_image() diff --git a/guizero/PushButton.py b/guizero/PushButton.py index 69483f8a..9b0570a9 100644 --- a/guizero/PushButton.py +++ b/guizero/PushButton.py @@ -74,9 +74,6 @@ def __init__( size. """ - - description = "[PushButton] object with text \"" + text + "\"" - self._value = 0 self._image_source = icon self._image_source = image @@ -90,7 +87,7 @@ def __init__( self._text.set(text) tk = Button(master.tk, textvariable=self._text, command=self._command_callback) - super(PushButton, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(PushButton, self).__init__(master, tk, grid, align, visible, enabled, width, height) # Add padding if necessary self.tk.config(pady=pady, padx=padx) @@ -146,8 +143,7 @@ def text(self): @text.setter def text(self, value): self._text.set(str(value)) - self.description = "[Text] object with text \"" + str(value) + "\"" - + @property def image(self): return self._image.image_source @@ -157,6 +153,12 @@ def image(self, value): self._image_source = value self._load_image() + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[PushButton] object with text '{}'".format(self.text) def resize(self, width, height): super(PushButton, self.__class__).resize(self, width, height) diff --git a/guizero/RadioButton.py b/guizero/RadioButton.py index a58024ff..7ea093bf 100644 --- a/guizero/RadioButton.py +++ b/guizero/RadioButton.py @@ -9,7 +9,6 @@ class RadioButton(TextWidget): def __init__(self, master, text, value, variable, command=None, grid=None, align=None, visible=True, enabled=None): - description = "[RadioButton] object with option=\"" + str(text) + "\" value=\"" + str(value) + "\"" self._text = text self._value = value @@ -18,7 +17,7 @@ def __init__(self, master, text, value, variable, command=None, grid=None, align # unless they know what they are doing. tk = Radiobutton(master.tk, text=self._text, value=self._value, variable=variable) - super(RadioButton, self).__init__(master, tk, description, grid, align, visible, enabled, None, None) + super(RadioButton, self).__init__(master, tk, grid, align, visible, enabled, None, None) # PROPERTIES # ----------------------------------- @@ -32,7 +31,6 @@ def value(self): def value(self, value): self._value = str(value) self.tk.config(value=str(value)) - self.description = "[RadioButton] object with option=\"" + self._text + "\" value=\"" + str(value) + "\"" # The text from this button @property @@ -43,4 +41,10 @@ def text(self): def text(self, text): self._text = str(text) self.tk.config(text=self._text) - self.description = "[RadioButton] object with option=\"" + str(text) + "\" value=\"" + self._value + "\"" + + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[RadioButton] object with option={} value={}".format(self.text, self.value) \ No newline at end of file diff --git a/guizero/Slider.py b/guizero/Slider.py index c8a32be3..0578128e 100644 --- a/guizero/Slider.py +++ b/guizero/Slider.py @@ -18,7 +18,8 @@ def __init__( width=None, height=None): - description = "[Slider] object from " + str(start) + " to " + str(end) + self._start = start + self._end = end # Set the direction self._horizontal = horizontal @@ -27,7 +28,7 @@ def __init__( # Create a tk Scale object within this object tk = Scale(master.tk, from_=start, to=end, orient=orient, command=self._command_callback) - super(Slider, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(Slider, self).__init__(master, tk, grid, align, visible, enabled, width, height) self.update_command(command) @@ -64,6 +65,12 @@ def _set_height(self, height): else: self._set_tk_config("length", height) + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[Slider] object from {} to {}".format(self._start, self._end) # METHODS # ---------------- diff --git a/guizero/Text.py b/guizero/Text.py index fa8e8da2..748ba799 100644 --- a/guizero/Text.py +++ b/guizero/Text.py @@ -19,11 +19,9 @@ def __init__( width=None, height=None): - description = "[Text] object with text \"" + str(text) + "\"" - self._text = str(text) tk = Label(master.tk, text=text) - super(Text, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(Text, self).__init__(master, tk, grid, align, visible, enabled, width, height) # setup defaults if bg: @@ -49,7 +47,6 @@ def value(self): def value(self, value): self.tk.config(text=value) self._text = str(value) - self.description = "[Text] object with text \"" + str(value) + "\"" # The font size @property @@ -60,6 +57,12 @@ def size(self): def size(self, size): self.text_size = size + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[Text] object with text '{}'".format(self.value) # METHODS # ------------------------------------------- @@ -74,5 +77,4 @@ def append(self, text): new_text = self._text + str(text) self._text = new_text self.tk.config(text=new_text) - self.description = "[Text] object with text \"" + new_text + "\"" diff --git a/guizero/TextBox.py b/guizero/TextBox.py index 535c7a68..c041bb05 100644 --- a/guizero/TextBox.py +++ b/guizero/TextBox.py @@ -20,8 +20,6 @@ def __init__( command=None, hide_text=False): - description = "[TextBox] object with text \"" + str(text) + "\"" - self._multiline = multiline # Set up controlling string variable @@ -38,7 +36,7 @@ def __init__( else: tk = Entry(master.tk, textvariable=self._text) - super(TextBox, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(TextBox, self).__init__(master, tk, grid, align, visible, enabled, width, height) self.hide_text = hide_text self.update_command(command) @@ -62,7 +60,6 @@ def value(self, value): if self._multiline: self.tk.delete(1.0,END) self.tk.insert(END,self._text.get()) - self.description = "[TextBox] object with text \"" + str(value) + "\"" def resize(self, width, height): self._width = width @@ -96,6 +93,13 @@ def hide_text(self, value): self._set_tk_config("show", show_value) + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[TextBox] object with text '{}'".format(self.value) + # METHODS # ------------------------------------------- def _key_released(self, event): diff --git a/guizero/Waffle.py b/guizero/Waffle.py index 059282bc..e20ac8a2 100644 --- a/guizero/Waffle.py +++ b/guizero/Waffle.py @@ -21,8 +21,6 @@ def __init__( enabled=None, bg=None): - description = "[Waffle] object ({}x{})".format(height, width) - # Create a tk Frame object within this object which will be the waffle tk = Frame(master.tk) @@ -35,7 +33,7 @@ def __init__( self._waffle_pixels = {} self._canvas = None - super(Waffle, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(Waffle, self).__init__(master, tk, grid, align, visible, enabled, width, height) if bg is not None: self.bg = bg @@ -270,6 +268,13 @@ def bg(self, value): super(Waffle, self.__class__).bg.fset(self, value) self._create_waffle() + @property + def description(self): + """ + Returns the description for the widget. + """ + return "[Waffle] object with text ({}x{})".format(self._height, self._width) + def reset(self): # reset all the colors and dottiness self.set_all(self._color) diff --git a/guizero/Window.py b/guizero/Window.py index c697914b..c7b162c7 100644 --- a/guizero/Window.py +++ b/guizero/Window.py @@ -15,15 +15,12 @@ def __init__( bg=None, visible=True): - description = "[Window] oject" - self._modal = False tk = Toplevel(master.tk) super(Window, self).__init__( master, tk, - description, title, width, height, diff --git a/guizero/base.py b/guizero/base.py index 0a2fe098..cad3dd40 100644 --- a/guizero/base.py +++ b/guizero/base.py @@ -98,6 +98,8 @@ def _set_tk_config(self, keys, value): else: self.tk[key] = value + def __repr__(self): + return "guizero.{} object".format(self.__class__.__name__) class Component( Base, @@ -107,14 +109,13 @@ class Component( ColorMixin, EventsMixin): - def __init__(self, master, tk, description, displayable): + def __init__(self, master, tk, displayable): """ An abstract class for a component in guizero. """ super(Component, self).__init__(tk) self._master = master - self._description = description self._events = EventManager(self, tk) self._displayable = displayable @@ -123,7 +124,7 @@ def __init__(self, master, tk, description, displayable): if isinstance(master, Container): self.master._add_child(self) else: - utils.raise_error("{}\nMaster is not an [App], [Window] or [Box]".format(description)) + utils.raise_error("{}\nMaster is not an [App], [Window] or [Box]".format(self.description)) @property def master(self): @@ -138,15 +139,11 @@ def master(self): @property def description(self): """ - Sets and returns the description for the widget. + Returns the description for the widget. """ - return self._description - - @description.setter - def description(self, value): - self._description = value + return "[{}] object".format(self.__class__.__name__) - def __repr__(self): + def __str__(self): return self.description @property @@ -178,11 +175,11 @@ def destroy(self): class Container(Component): - def __init__(self, master, tk, description, layout, displayable): + def __init__(self, master, tk, layout, displayable): """ An abstract class for a container which can hold other widgets. """ - super(Container, self).__init__(master, tk, description, displayable) + super(Container, self).__init__(master, tk, displayable) self._children = [] self._layout_manager = layout self._bg = None @@ -317,7 +314,7 @@ def add_tk_widget(self, tk_widget, grid=None, align=None, visible=True, enabled= # raise a warning if the tk widgets master is not this container if self.tk is not tk_widget.master: utils.error_format("The tk widget's master is not '{}'.\nIt may not display correctly.".format(self.description)) - return Widget(self, tk_widget, "tk widget", grid, align, visible, enabled, width, height) + return Widget(self, tk_widget, grid, align, visible, enabled, width, height) def _add_child(self, child): """ @@ -441,11 +438,11 @@ def enable(self): class BaseWindow(Container): - def __init__(self, master, tk, description, title, width, height, layout, bg, visible): + def __init__(self, master, tk, title, width, height, layout, bg, visible): """ Base class for objects which use windows e.g. `App` and `Window` """ - super(BaseWindow, self).__init__(master, tk, description, layout, False) + super(BaseWindow, self).__init__(master, tk, layout, False) # Initial setup self.tk.title( str(title) ) @@ -609,11 +606,11 @@ class Widget( SizeMixin, LayoutMixin): - def __init__(self, master, tk, description, grid, align, visible, enabled, width, height): + def __init__(self, master, tk, grid, align, visible, enabled, width, height): """ The base class for a widget which is an interactable component e.g. `Picture` """ - super(Widget, self).__init__(master,tk, description, True) + super(Widget, self).__init__(master,tk, True) self._update_grid(grid) self._update_align(align) self._width = width @@ -635,11 +632,11 @@ class TextWidget( Widget, TextMixin): - def __init__(self, master, tk, description, grid, align, visible, enabled, width, height): + def __init__(self, master, tk, grid, align, visible, enabled, width, height): """ The base class for a widget which contains or has text e.g. ``Text`, `PushButton` """ - super(TextWidget, self).__init__(master, tk, description, grid, align, visible, enabled, width, height) + super(TextWidget, self).__init__(master, tk, grid, align, visible, enabled, width, height) #inherit from master self.text_color = master.text_color @@ -654,11 +651,11 @@ class ContainerWidget( SizeMixin, LayoutMixin): - def __init__(self, master, tk, description, layout, grid, align, visible, enabled, width, height): + def __init__(self, master, tk, layout, grid, align, visible, enabled, width, height): """ The base class for a widget which is also a container e.g. `Box`, `ButtonGroup` """ - super(ContainerWidget, self).__init__(master,tk, description, layout, True) + super(ContainerWidget, self).__init__(master, tk, layout, True) self._update_grid(grid) self._update_align(align) self._width = width @@ -715,9 +712,9 @@ class ContainerTextWidget( ContainerWidget, TextMixin): - def __init__(self, master, tk, description, layout, grid, align, visible, enabled, width, height): + def __init__(self, master, tk, layout, grid, align, visible, enabled, width, height): """ The base class for a widget which is also a container and contains text e.g. `ButtonGroup` """ - super(ContainerTextWidget, self).__init__(master, tk, description, layout, grid, align, visible, enabled, width, height) + super(ContainerTextWidget, self).__init__(master, tk, layout, grid, align, visible, enabled, width, height) From c63b46772618e5a47ad84abf823fba01eb1cde0b Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Thu, 19 Nov 2020 08:53:34 +0000 Subject: [PATCH 03/12] disabled text --- guizero/TextBox.py | 8 ++++++++ tests/test_textbox.py | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/guizero/TextBox.py b/guizero/TextBox.py index c041bb05..2e98cdb9 100644 --- a/guizero/TextBox.py +++ b/guizero/TextBox.py @@ -56,11 +56,19 @@ def value(self): @value.setter def value(self, value): + # if the TextBox is disabled, enable it so they value can be set + was_disabled = not self.enabled + if was_disabled: + self.enabled = True + self._text.set( str(value) ) if self._multiline: self.tk.delete(1.0,END) self.tk.insert(END,self._text.get()) + if was_disabled: + self.enabled = False + def resize(self, width, height): self._width = width if width != "fill": diff --git a/tests/test_textbox.py b/tests/test_textbox.py index 7efe977c..67398c61 100644 --- a/tests/test_textbox.py +++ b/tests/test_textbox.py @@ -172,4 +172,11 @@ def test_grid_layout(): wa = TextBox(a, grid=[1,2], align="top") grid_layout_test(wa, 1, 2, 1, 1, "top") - a.destroy() \ No newline at end of file + a.destroy() + +def test_disabled_text(): + a = App() + t = TextBox(a, enabled=False) + t.text = "text" + assert t.text == "text" + a.destroy() From 4c9838550b443228a878967d0f74961596ec5af2 Mon Sep 17 00:00:00 2001 From: martinohanlon Date: Thu, 19 Nov 2020 16:24:16 +0000 Subject: [PATCH 04/12] fix macos image pushbutton issue --- guizero/PushButton.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guizero/PushButton.py b/guizero/PushButton.py index 9b0570a9..c2f8ac20 100644 --- a/guizero/PushButton.py +++ b/guizero/PushButton.py @@ -102,6 +102,9 @@ def __init__( self._load_image() def _load_image(self): + # clear the text on the button if an image is being loaded + self._text.set("") + if self._height == "fill" or self._width == "fill": utils.raise_error("{}\nCannot use 'fill' for width and height when using a image.".format(self.description)) From 6222c74b4747115842666a6503a3f6198d82c92f Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Thu, 19 Nov 2020 16:39:35 +0000 Subject: [PATCH 05/12] clearing an image --- guizero/PushButton.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/guizero/PushButton.py b/guizero/PushButton.py index c2f8ac20..861c6a17 100644 --- a/guizero/PushButton.py +++ b/guizero/PushButton.py @@ -145,16 +145,20 @@ def text(self): # Set the text on the button @text.setter def text(self, value): + # clear any existing image from the button + self._clear_image() self._text.set(str(value)) @property def image(self): - return self._image.image_source - + return None if self._image is None else self._image.image_source + @image.setter def image(self, value): - self._image_source = value - self._load_image() + self._clear_image() + if value is not None: + self._image_source = value + self._load_image() @property def description(self): @@ -163,12 +167,6 @@ def description(self): """ return "[PushButton] object with text '{}'".format(self.text) - def resize(self, width, height): - super(PushButton, self.__class__).resize(self, width, height) - - if self._image: - self._load_image() - # METHODS # ------------------------------------------- # Internal use only @@ -197,6 +195,23 @@ def update_command(self, command, args=None): self._command = command else: self._command = utils.with_args(command, *args) + + def resize(self, width, height): + super(PushButton, self.__class__).resize(self, width, height) + + if self._image: + self._load_image() def _command_callback(self): self._command() + + def _clear_image(self): + if self._image: + self._image_source = None + self._image = None + self._image_height = None + self._image_width = None + self._image_player = None + self.tk.config(image="") + self.resize(None, None) + self._text.set(str("Button")) \ No newline at end of file From 75da5ce988a4418675ba90f67b94f59c4d2a93cd Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Fri, 20 Nov 2020 07:42:41 +0000 Subject: [PATCH 06/12] description test --- tests/test_app.py | 1 + tests/test_box.py | 1 + tests/test_buttongroup.py | 1 + tests/test_checkbox.py | 1 + tests/test_combo.py | 1 + tests/test_drawing.py | 1 + tests/test_listbox.py | 1 + tests/test_menubar.py | 1 + tests/test_picture.py | 1 + tests/test_pushbutton.py | 1 + tests/test_slider.py | 1 + tests/test_text.py | 1 + tests/test_textbox.py | 1 + tests/test_waffle.py | 1 + tests/test_window.py | 1 + 15 files changed, 15 insertions(+) diff --git a/tests/test_app.py b/tests/test_app.py index c10f035b..ce4aa81a 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -16,6 +16,7 @@ def test_default_values(): assert a.width == 500 assert a.height == 500 assert a.layout == "auto" + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_box.py b/tests/test_box.py index 6c2df8cc..8b9b3d11 100644 --- a/tests/test_box.py +++ b/tests/test_box.py @@ -23,6 +23,7 @@ def test_default_values(): assert b.layout == "auto" assert b.grid == None assert b.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_buttongroup.py b/tests/test_buttongroup.py index 59fe9231..b7561f04 100644 --- a/tests/test_buttongroup.py +++ b/tests/test_buttongroup.py @@ -25,6 +25,7 @@ def test_default_values(): assert b.value_text == "foo" assert b.grid == None assert b.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_checkbox.py b/tests/test_checkbox.py index 06077fc6..3b44a2a9 100644 --- a/tests/test_checkbox.py +++ b/tests/test_checkbox.py @@ -24,6 +24,7 @@ def test_default_values(): assert c.text == "foo" assert c.grid == None assert c.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_combo.py b/tests/test_combo.py index c1fa9ad6..ca01d120 100644 --- a/tests/test_combo.py +++ b/tests/test_combo.py @@ -24,6 +24,7 @@ def test_default_values(): assert c.value == "foo" assert c.grid == None assert c.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_drawing.py b/tests/test_drawing.py index 599dd326..2d4df84e 100644 --- a/tests/test_drawing.py +++ b/tests/test_drawing.py @@ -21,6 +21,7 @@ def test_default_values(): assert d.align == None assert d.width == 100 assert d.height == 100 + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_listbox.py b/tests/test_listbox.py index d7be6025..326f33b6 100644 --- a/tests/test_listbox.py +++ b/tests/test_listbox.py @@ -28,6 +28,7 @@ def test_default_values(): assert l.visible == True assert l.enabled == True assert l._listbox._multiselect == False + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_menubar.py b/tests/test_menubar.py index b0838e0a..72f48a10 100644 --- a/tests/test_menubar.py +++ b/tests/test_menubar.py @@ -24,6 +24,7 @@ def callback(): assert m.master == a assert not callback_event.is_set() + assert a.description > "" # menu invoke doesnt work... # m.tk.invoke(0) diff --git a/tests/test_picture.py b/tests/test_picture.py index e81bf967..f9d0358c 100644 --- a/tests/test_picture.py +++ b/tests/test_picture.py @@ -22,6 +22,7 @@ def test_default_values(): assert p.image == None assert p.grid == None assert p.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_pushbutton.py b/tests/test_pushbutton.py index 39a090e0..6705a23e 100644 --- a/tests/test_pushbutton.py +++ b/tests/test_pushbutton.py @@ -25,6 +25,7 @@ def test_default_values(): assert b.text == "Button" assert b.grid == None assert b.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_slider.py b/tests/test_slider.py index 367b3d8d..e12c904f 100644 --- a/tests/test_slider.py +++ b/tests/test_slider.py @@ -26,6 +26,7 @@ def test_default_values(): assert s.master == a assert s.grid == None assert s.align == None + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_text.py b/tests/test_text.py index 676cb08d..f02e8f30 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -29,6 +29,7 @@ def test_default_values(): # test for different fonts to support tests on windows, debian and macos assert (t.font == "Arial" or t.font == "Nimbus Sans L" or t.font == "Helvetica") assert t.value == "" + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_textbox.py b/tests/test_textbox.py index 67398c61..d964d24c 100644 --- a/tests/test_textbox.py +++ b/tests/test_textbox.py @@ -24,6 +24,7 @@ def test_default_values(): assert t.align == None assert t.width == 10 assert t.value == "" + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_waffle.py b/tests/test_waffle.py index 00754a33..679ee094 100644 --- a/tests/test_waffle.py +++ b/tests/test_waffle.py @@ -27,6 +27,7 @@ def test_default_values(): assert w.pad == 5 assert w.color == "white" assert w.dotty == False + assert a.description > "" a.destroy() def test_alt_values(): diff --git a/tests/test_window.py b/tests/test_window.py index 68b772d0..3506d6fb 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -19,6 +19,7 @@ def test_default_values(): assert w.width == 500 assert w.height == 500 assert w.layout == "auto" + assert a.description > "" a.destroy() def test_alt_values(): From 68f860c6ab2a95be9e664b4fa0440bda0cb0b1be Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Tue, 24 Nov 2020 12:13:02 +0000 Subject: [PATCH 07/12] fix listbox scrollbar issue and add tests to cover --- guizero/ListBox.py | 2 +- tests/test_listbox.py | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/guizero/ListBox.py b/guizero/ListBox.py index 3a434b96..8fdf7add 100644 --- a/guizero/ListBox.py +++ b/guizero/ListBox.py @@ -76,7 +76,7 @@ def __init__( if scrollbar: # create the scrollbar and add it to the listbox scrollbar_tk_widget = Scrollbar(tk) - Widget(self, scrollbar_tk_widget, "scrollbar", None, "right", True, True, None, "fill") + Widget(self, scrollbar_tk_widget, None, "right", True, True, None, "fill") self._listbox.tk.config(yscrollcommand=scrollbar_tk_widget.set) scrollbar_tk_widget.config(command=self._listbox.tk.yview) diff --git a/tests/test_listbox.py b/tests/test_listbox.py index 326f33b6..89631906 100644 --- a/tests/test_listbox.py +++ b/tests/test_listbox.py @@ -40,7 +40,8 @@ def test_alt_values(): grid = [0,1], align = "top", width=10, - height=11) + height=11, + scrollbar=True) assert l.value == "bar" assert l.items == ["foo", "bar"] @@ -52,6 +53,19 @@ def test_alt_values(): a.destroy() +def test_multi_default_values(): + a = App() + l = ListBox(a, multiselect = True) + assert l.master == a + assert l.value == None + assert l.items == [] + assert l.grid == None + assert l.align == None + assert l.visible == True + assert l.enabled == True + assert l._listbox._multiselect == True + a.destroy() + def test_multi_alt_values(): a = App(layout = "grid") l = ListBox( @@ -60,7 +74,8 @@ def test_multi_alt_values(): selected = ["bar"], grid = [0,1], align = "top", - multiselect = True) + multiselect = True, + scrollbar=True) assert l.value == ["bar"] assert l.items == ["foo", "bar"] @@ -289,4 +304,6 @@ def test_grid_layout(): wa = ListBox(a, grid=[1,2], align="top") grid_layout_test(wa, 1, 2, 1, 1, "top") - a.destroy() \ No newline at end of file + a.destroy() + +test_multi_alt_values() From 58eb1f7ddaec80cac0bf51fff2da0dcfec97c57d Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Fri, 27 Nov 2020 10:58:27 +0000 Subject: [PATCH 08/12] using tk documentation updates --- docs-src/docs/app.md | 6 ++-- docs-src/docs/box.md | 5 ++- docs-src/docs/buttongroup.md | 56 +++++++++++++++++++++------------ docs-src/docs/checkbox.md | 61 ++++++++++++++++++------------------ docs-src/docs/combo.md | 40 +++++++++++------------ docs-src/docs/drawing.md | 3 +- docs-src/docs/listbox.md | 36 ++++++++++++++++----- docs-src/docs/menubar.md | 9 +++--- docs-src/docs/picture.md | 3 +- docs-src/docs/pushbutton.md | 3 +- docs-src/docs/slider.md | 3 +- docs-src/docs/text.md | 3 +- docs-src/docs/textbox.md | 3 +- docs-src/docs/waffle.md | 33 ++++++++++--------- docs-src/docs/window.md | 5 ++- guizero/ListBox.py | 6 +++- 16 files changed, 151 insertions(+), 124 deletions(-) diff --git a/docs-src/docs/app.md b/docs-src/docs/app.md index 88db66c1..6bc7d7cd 100644 --- a/docs-src/docs/app.md +++ b/docs-src/docs/app.md @@ -1,7 +1,5 @@ # App -(Contains a `tkinter.Tk` object) - ```python __init__( self, @@ -80,7 +78,7 @@ You can set and get the following properties: | Method | Data type | Description | |-------------|--------------------|--------------------------------------------------------------------------------------------| | bg | [color](colors.md) | The background colour of the window | -| children | list(widgets) | A list of widgets in this container | +| children | List | A list of widgets in this container | | enabled | boolean | `True` if the app is enabled | | height | int | The height of the window | | font | string | The font that widgets should use | @@ -89,11 +87,11 @@ You can set and get the following properties: | title | string | The title of the window | | text_size | int | The size of the text widgets should use | | text_color | [color](colors.md) | The colour of the text widgets should use | +| tk | tkinter.Tk | The internal tkinter object, see [Using tkinter](usingtk.md) | | visible | boolean | If the app is visible | | width | int | The width of the window | | when_closed | function | The function to call when the `App` is closed. Setting to `None` (the default) will reset. | - Refer to a property as `.property`. For example, if your `App` object is called `app` you would write `app.title`. You can **set** the property (for example `app.title = "Hello world"`) or **get** the value of the property to use (for example `print(app.title)`). diff --git a/docs-src/docs/box.md b/docs-src/docs/box.md index c17a4a19..fc3c9edd 100644 --- a/docs-src/docs/box.md +++ b/docs-src/docs/box.md @@ -1,7 +1,5 @@ # Box -(Contains a `tkinter.Frame` object) - ```python __init__( self, @@ -78,7 +76,7 @@ You can set and get the following properties: | align | string | The alignment of this widget within its container | | border | int | The border thickness, setting to `0` or `False` (the default) there is no border. | | bg | [color](colors.md) | The background colour of the widget | -| children | list(widgets) | A list of widgets in this container | +| children | List | A list of widgets in this container | | enabled | boolean | `True` if the box is enabled | | grid | List | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid | | font | string | The font that widgets should use | @@ -87,6 +85,7 @@ You can set and get the following properties: | master | App | The `App` object to which this box belongs | | text_size | int | The size of the text widgets should use | | text_color | [color](colors.md) | The colour of the text widgets should use | +| tk | tkinter.Frame | The internal tkinter object, see [Using tkinter](usingtk.md) | | visible | boolean | If this widget is visible | | width | [size](size.md) | Set the width of the widget in pixels or to `"fill"` | diff --git a/docs-src/docs/buttongroup.md b/docs-src/docs/buttongroup.md index 8297e9cb..12be70b0 100644 --- a/docs-src/docs/buttongroup.md +++ b/docs-src/docs/buttongroup.md @@ -1,7 +1,5 @@ # ButtonGroup -(Contains a `tkinter.Frame` object) - ```python __init__( self, @@ -59,23 +57,23 @@ When you create a `ButtonGroup` object you **must** specify a `master` and you c You can call the following methods on an `ButtonGroup` object. -| Method | Takes | Returns | Description | -|-------------------------------------|--------------------------------------------------------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| -| append(option) | item (string) | - | Appends a new `option` to the end of the ButtonGroup. | -| after(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) | -| cancel(command) | command (function name) | - | Cancels a scheduled call to `command` | -| destroy() | - | - | Destroys the widget | -| disable() | - | - | Disables the widget so that it is "greyed out" and cannot be interacted with | -| enable() | - | - | Enables the widget | -| focus() | - | - | Gives focus to the widget | -| get_group_as_list() | - | list | Returns a list containing all of the text/hidden value pairs from the ButtonGroup (useful for debugging) | -| hide() | - | - | Hides the widget from view. This method will unpack the widget from the layout manager. | -| insert(index, option) | index (int), option (string) | - | Insert a new `option` in the ButtonGroup at `index` | -| remove(option) | item (string) | Boolean | Removes the first `option` from the ButtonGroup. Returns `True` if an item was removed. | -| repeat(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Repeats `command` every `time` milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. | -| resize(width, height) | width (int), height (int) | - | Sets the width and height of the widget | -| show() | - | - | Displays the widget if it was previously hidden | -| update_command(command, args =None) | command (function name), args (_Optional_ List of arguments to be passed to command) | - | Updates the function to call when the selected option changes | +| Method | Takes | Returns | Description | +|-------------------------------------|--------------------------------------------------------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| append(option) | item (string) | - | Appends a new `option` to the end of the ButtonGroup. | +| after(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) | +| cancel(command) | command (function name) | - | Cancels a scheduled call to `command` | +| destroy() | - | - | Destroys the widget | +| disable() | - | - | Disables the widget so that it is "greyed out" and cannot be interacted with | +| enable() | - | - | Enables the widget | +| focus() | - | - | Gives focus to the widget | +| get_group_as_list() | - | list | Returns a list containing all of the text/hidden value pairs from the ButtonGroup (useful for debugging) | +| hide() | - | - | Hides the widget from view. This method will unpack the widget from the layout manager. | +| insert(index, option) | index (int), option (string) | - | Insert a new `option` in the ButtonGroup at `index` | +| remove(option) | item (string) | Boolean | Removes the first `option` from the ButtonGroup. Returns `True` if an item was removed. | +| repeat(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Repeats `command` every `time` milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. | +| resize(width, height) | width (int), height (int) | - | Sets the width and height of the widget | +| show() | - | - | Displays the widget if it was previously hidden | +| update_command(command, args =None) | command (function name), args (_Optional_ List of arguments to be passed to command) | - | Updates the function to call when the selected option changes | ### Properties @@ -86,6 +84,7 @@ You can set and get the following properties: |------------|--------------------|-------------------------------------------------------------------------------------------------------| | align | string | The alignment of this widget within its container | | bg | [color](colors.md) | The background colour of the widget | +| children | List | A list of the widgets in this container. `[RadioButton, *]` | | enabled | boolean | `True` if the widget is enabled | | font | string | The font of the text | | grid | List | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid | @@ -97,7 +96,7 @@ You can set and get the following properties: | width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | | text_size | int | The size of the text | | text_color | [color](colors.md) | The colour of the text | - +| tk | tkinter.Frame | The internal tkinter object, see [Using tkinter](usingtk.md) | Refer to a property as `.property`. For example, if your `ButtonGroup` object is called `choice` you would write `choice.value`. @@ -126,3 +125,20 @@ activities = ButtonGroup(app, options=[ what_is_selected = Text(app, text="skate") app.display() ``` + +### Using ButtonGroup tk widgets + +Advanced users can gain internal access to the internal tkinter widgets used by `ButtonGroup`. For more information on using tkinter in combination with guizero see [Using tkinter](usingtk.md). + +The `ButtonGroup` widget contains a `tkinter.Frame` object, which frames multiple guizero `RadioButton` widgets. Each `RadioButton` widget contains a `tkinter.Radiobutton` object. + +The `.children` property returns the list of `RadioButton` widgets in the order they appear in the `ButtonGroup`: + +To access the internal `RadioButton` tk object you would use the child's `tk` property e.g. + +```python +button_group = ButtonGroup(app) + +for radio_button in ButtonGroup.children: + tk_radio_button = radio_button.tk +``` \ No newline at end of file diff --git a/docs-src/docs/checkbox.md b/docs-src/docs/checkbox.md index 007cb81b..0d778878 100644 --- a/docs-src/docs/checkbox.md +++ b/docs-src/docs/checkbox.md @@ -1,7 +1,5 @@ # CheckBox -(Contains a `tkinter.Checkbutton` object) - ```python __init__( self, @@ -55,41 +53,42 @@ When you create a `CheckBox` object you **must** specify `master` and `text` and You can call the following methods on a `CheckBox` object. -| Method | Takes | Returns | Description | -|-------------------------------------|--------------------------------------------------------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| -| after(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) | -| cancel(command) | command (function name) | - | Cancels a scheduled call to `command` | -| destroy() | - | - | Destroys the widget | -| disable() | - | - | Disables the widget so that it is "greyed out" and cannot be interacted with | -| enable() | - | - | Enables the widget | -| focus() | - | - | Gives focus to the widget | -| hide() | - | - | Hides the widget from view. This method will unpack the widget from the layout manager. | -| repeat(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Repeats `command` every `time` milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. | -| resize(width, height) | width (int), height (int) | - | Sets the width and height of the widget | -| show() | - | - | Displays the widget if it was previously hidden | -| toggle() | - | - | Switches the `CheckBox` to the opposite of its current value. i.e. if it is ticked, untick it and vice versa | -| update_command(command, args =None) | command (function name), args (_Optional_ List of arguments to be passed to command) | - | Updates the function to call when the checkbox is ticked/unticked | +| Method | Takes | Returns | Description | +|-------------------------------------|--------------------------------------------------------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| after(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) | +| cancel(command) | command (function name) | - | Cancels a scheduled call to `command` | +| destroy() | - | - | Destroys the widget | +| disable() | - | - | Disables the widget so that it is "greyed out" and cannot be interacted with | +| enable() | - | - | Enables the widget | +| focus() | - | - | Gives focus to the widget | +| hide() | - | - | Hides the widget from view. This method will unpack the widget from the layout manager. | +| repeat(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Repeats `command` every `time` milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. | +| resize(width, height) | width (int), height (int) | - | Sets the width and height of the widget | +| show() | - | - | Displays the widget if it was previously hidden | +| toggle() | - | - | Switches the `CheckBox` to the opposite of its current value. i.e. if it is ticked, untick it and vice versa | +| update_command(command, args =None) | command (function name), args (_Optional_ List of arguments to be passed to command) | - | Updates the function to call when the checkbox is ticked/unticked | ### Properties You can set and get the following properties: -| Method | Data type | Description | -|------------|--------------------|-------------------------------------------------------------------------------------------------------| -| align | string | The alignment of this widget within its container | -| bg | [color](colors.md) | The background colour of the widget | -| enabled | boolean | `True` if the widget is enabled | -| font | string | The font of the text | -| grid | List | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid | -| height | [size](size.md) | Set the height of the widget in characters or to `"fill"` | -| master | App or Box | The container to which this widget belongs | -| text | string | The text associated with the checkbox | -| value | int | `1` if the CheckBox is ticked or `0` if it is not ticked | -| visible | boolean | If this widget is visible | -| width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | -| text_size | int | The size of the text | -| text_color | [color](colors.md) | The colour of the text | +| Method | Data type | Description | +|------------|---------------------|-------------------------------------------------------------------------------------------------------| +| align | string | The alignment of this widget within its container | +| bg | [color](colors.md) | The background colour of the widget | +| enabled | boolean | `True` if the widget is enabled | +| font | string | The font of the text | +| grid | List | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid | +| height | [size](size.md) | Set the height of the widget in characters or to `"fill"` | +| master | App or Box | The container to which this widget belongs | +| text | string | The text associated with the checkbox | +| value | int | `1` if the CheckBox is ticked or `0` if it is not ticked | +| visible | boolean | If this widget is visible | +| width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | +| text_size | int | The size of the text | +| text_color | [color](colors.md) | The colour of the text | +| tk | tkinter.Checkbutton | The internal tkinter object, see [Using tkinter](usingtk.md) | Refer to a property as `.property`. For example, if your `CheckBox` object is called `checkbox` you would write `checkbox.value`. diff --git a/docs-src/docs/combo.md b/docs-src/docs/combo.md index 6ff0871c..461cd992 100644 --- a/docs-src/docs/combo.md +++ b/docs-src/docs/combo.md @@ -1,7 +1,5 @@ # Combo -(Contains a `tkinter.OptionMenu` object) - ```python __init__( self, @@ -56,24 +54,24 @@ When you create a `Combo` object you **must** specify a `master` and you can sp You can call the following methods on a `Combo` object. -| Method | Takes | Returns | Description | -|----------------------------------|---------------------------------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| -| append(option) | item (string) | - | Appends a new `option` to the end of the Combo. | -| after(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) | -| cancel(command) | command (function name) | - | Cancels a scheduled call to `command` | -| clear() | - | - | Removes all options from the Combo box | -| destroy() | - | - | Destroys the widget | -| disable() | - | - | Disables the widget so that it is "greyed out" and cannot be interacted with | -| enable() | - | - | Enables the widget | -| focus() | - | - | Gives focus to the widget | -| hide() | - | - | Hides the widget from view. This method will unpack the widget from the layout manager. | -| insert(index, option) | index (int), item (string) | - | Insert a new `option` in the Combo at `index` | -| remove(option) | item (string) | Boolean | Removes the first `option` from the Combo. Returns `True` if an item was removed. | -| repeat(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Repeats `command` every `time` milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. | -| resize(width, height) | width (int), height (int) | - | Sets the width and height of the widget | -| select_default() | - | - | Resets the combo box so that the first item is selected | -| show() | - | - | Displays the widget if it was previously hidden | -| update_command(command) | command (function name) | - | Updates the function to call when a different option is selected. | +| Method | Takes | Returns | Description | +|----------------------------------|---------------------------------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| append(option) | item (string) | - | Appends a new `option` to the end of the Combo. | +| after(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) | +| cancel(command) | command (function name) | - | Cancels a scheduled call to `command` | +| clear() | - | - | Removes all options from the Combo box | +| destroy() | - | - | Destroys the widget | +| disable() | - | - | Disables the widget so that it is "greyed out" and cannot be interacted with | +| enable() | - | - | Enables the widget | +| focus() | - | - | Gives focus to the widget | +| hide() | - | - | Hides the widget from view. This method will unpack the widget from the layout manager. | +| insert(index, option) | index (int), item (string) | - | Insert a new `option` in the Combo at `index` | +| remove(option) | item (string) | Boolean | Removes the first `option` from the Combo. Returns `True` if an item was removed. | +| repeat(time, command, args=None) | time (int), command (function name), args (list of arguments) | - | Repeats `command` every `time` milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. | +| resize(width, height) | width (int), height (int) | - | Sets the width and height of the widget | +| select_default() | - | - | Resets the combo box so that the first item is selected | +| show() | - | - | Displays the widget if it was previously hidden | +| update_command(command) | command (function name) | - | Updates the function to call when a different option is selected. | @@ -95,7 +93,7 @@ You can set and get the following properties: | width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | | text_size | int | The size of the text | | text_color | [color](colors.md) | The colour of the text | - +| tk | tkinter.OptionMenu | The internal tkinter object, see [Using tkinter](usingtk.md) | Refer to a property as `.property`. For example, if your `Combo` object is called `combo` you would write `combo.value`. diff --git a/docs-src/docs/drawing.md b/docs-src/docs/drawing.md index 14bacfd6..9fd840ad 100644 --- a/docs-src/docs/drawing.md +++ b/docs-src/docs/drawing.md @@ -1,7 +1,5 @@ # Drawing -(Contains a `tkinter.canvas` object) - ```python __init__( self, @@ -86,6 +84,7 @@ You can set and get the following properties: | grid | List | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid | | height | [size](size.md) | Set the height of the widget in characters or to `"fill"` | | master | App or Box | The container to which this widget belongs | +| tk | tkinter.canvas | The internal tkinter object, see [Using tkinter](usingtk.md) | | visible | boolean | If this widget is visible | | width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | diff --git a/docs-src/docs/listbox.md b/docs-src/docs/listbox.md index fb92063f..3df4984d 100644 --- a/docs-src/docs/listbox.md +++ b/docs-src/docs/listbox.md @@ -1,7 +1,5 @@ # ListBox -(Contains a `tkinter.Listbox` object) - ```python __init__( self, @@ -53,8 +51,8 @@ If you want the `ListBox` to allow multiple items to be selected you must set th | enabled | boolean | None | No | If the widget should be enabled. If `None` (the default) the enabled property will be inherited from the master | | multiselect | boolean | False | No | If the widget should allow multiple items to be selected. | | scrollbar | boolean | False | No | If the widget should have a verticle scrollbar. | -| width | [size](size.md) | None | No | Set the width of the widget in pixels or to `"fill"` | -| height | [size](size.md) | None | No | Set the height of the widget in pixels or to `"fill"` | +| width | [size](size.md) | None | No | Set the width of the widget in pixels or to `"fill"` | +| height | [size](size.md) | None | No | Set the height of the widget in pixels or to `"fill"` | ### Methods @@ -88,17 +86,19 @@ You can set and get the following properties: |------------|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | align | string | The alignment of this widget within its container | | bg | [color](colors.md) | The background colour of the widget | +| children | List | A list of the widgets in this container. `[ListBoxWidget, ListBoxScrollbar]` | | enabled | boolean | `True` if the widget is enabled | | font | string | The font of the text | | grid | List | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid | -| height | [size](size.md) | Set the height of the widget in pixels or to `"fill"` | +| height | [size](size.md) | Set the height of the widget in pixels or to `"fill"` | | items | List | Returns a list of items in the ListBox | | master | App or Box | The container to which this widget belongs | | value | string | Sets or returns the items selected in a ListBox. Returns `None` if 0 items are selected. If the ListBox is a not `multiselect`, `value` is the item selected, if the ListBox is a `multiselect`, `value` is a list of items selected. | | visible | boolean | If this widget is visible | -| width | [size](size.md) | Set the width of the widget in pixels or to `"fill"` | +| width | [size](size.md) | Set the width of the widget in pixels or to `"fill"` | | text_size | int | The size of the text | | text_color | [color](colors.md) | The colour of the text | +| tk | tkinter.Frame | The internal tkinter object, see [Using tkinter](usingtk.md) | Refer to a property as `.property`. For example, if your `ListBox` object is called `listbox` you would write `listbox.value`. @@ -131,4 +131,26 @@ listbox = ListBox( a.display() ``` -![A list of colors](images/listbox_color_changer_windows.png) \ No newline at end of file +![A list of colors](images/listbox_color_changer_windows.png) + +### Using ListBox tk widgets + +Advanced users can gain internal access to the internal tkinter widgets used by `ListBox`. For more information on using tkinter in combination with guizero see [Using tkinter](usingtk.md). + +The `ListBox` widget contains a `tkinter.Frame` object, which frames 2 other child guizero widgets containing `tkinter.Listbox` and `tkinter.Scrollbar` objects. + +The `.children` property returns a list of these widgets: + +| .children index | guizero class | tk class | notes | +|-----------------|--------------------|---------------------|-------------------------------------------------------------------------------------------| +| 0 | `ListBoxWidget` | `tkinter.Listbox` | | +| 1 | `ListBoxScrollbar` | `tkinter.Scrollbar` | A `ListBoxScrollbar` widget will only be present if `ListBox.scrollbar` is set to `True`. | + +To access the internal tk object for these child guizero widgets you would use its `tk` property e.g. + +```python +listbox = listBox(app) + +tk_listbox = listbox.children[0].tk +tk_scrollbar = listbox.children[1].tk +``` \ No newline at end of file diff --git a/docs-src/docs/menubar.md b/docs-src/docs/menubar.md index d0959797..ca8327ac 100644 --- a/docs-src/docs/menubar.md +++ b/docs-src/docs/menubar.md @@ -1,7 +1,5 @@ # MenuBar -(Contains a `tkinter.Menu` object) - ```python __init__( self, @@ -79,6 +77,7 @@ You can call the following methods on an `MenuBar` object. You can set and get the following properties: -| Method | Data type | Description | -|--------|-----------|------------------------------------------------| -| master | App | The `App` object to which this MenuBar belongs | +| Method | Data type | Description | +|--------|--------------|--------------------------------------------------------------| +| master | App | The `App` object to which this MenuBar belongs | +| tk | tkinter.Menu | The internal tkinter object, see [Using tkinter](usingtk.md) | \ No newline at end of file diff --git a/docs-src/docs/picture.md b/docs-src/docs/picture.md index 99f710a3..52fdd774 100644 --- a/docs-src/docs/picture.md +++ b/docs-src/docs/picture.md @@ -1,7 +1,5 @@ # Picture -(Contains a `tkinter.Label` object) - ```python __init__( self, @@ -89,6 +87,7 @@ You can set and get the following properties: | height | [size](size.md) | Set the height of the widget in pixels | | image | string | The file path, tkinter.PhotoImage or PIL.Image you wish to display | | master | App or Box | The container to which this widget belongs | +| tk | tkinter.Label | The internal tkinter object, see [Using tkinter](usingtk.md) | | value | string | The file path, tkinter.PhotoImage or PIL.Image you wish to display | | visible | boolean | If this widget is visible | | width | [size](size.md) | Set the width of the widget in pixels | diff --git a/docs-src/docs/pushbutton.md b/docs-src/docs/pushbutton.md index 5677d15f..f3422711 100644 --- a/docs-src/docs/pushbutton.md +++ b/docs-src/docs/pushbutton.md @@ -1,7 +1,5 @@ # PushButton -(Contains a `tkinter.Button` object) - ```python __init__( self, @@ -113,6 +111,7 @@ You can set and get the following properties: | text | string | The text on the button | | text_color | [color](colors.md) | The colour of the text on the button | | text_size | int | The size of the text on the button | +| tk | tkinter.Button | The internal tkinter object, see [Using tkinter](usingtk.md) | | value | int | Returns 1 when the button is pressed, 0 if the button is released | | visible | boolean | If this widget is visible | | width | [size](size.md) | Set the width of the widget in characters or pixels if its an image button or to `"fill"` | diff --git a/docs-src/docs/slider.md b/docs-src/docs/slider.md index be0cc0bc..bcc1cf15 100644 --- a/docs-src/docs/slider.md +++ b/docs-src/docs/slider.md @@ -1,7 +1,5 @@ # Slider -(Contains a `tkinter.Scale` object) - ```python __init__( self, @@ -89,6 +87,7 @@ You can set and get the following properties: | master | App or Box | The container to which this widget belongs | | text_size | int | The size of the text | | text_color | [color](colors.md) | The colour of the text | +| tk | tkinter.Scale | The internal tkinter object, see [Using tkinter](usingtk.md) | | value | string | The current value of the slider | | visible | boolean | If this widget is visible | | width | [size](size.md) | Set the width of the widget in pixels or to `"fill"` | diff --git a/docs-src/docs/text.md b/docs-src/docs/text.md index 46710cee..50b1110f 100644 --- a/docs-src/docs/text.md +++ b/docs-src/docs/text.md @@ -1,7 +1,5 @@ # Text -(Contains a `tkinter.Label` object) - ```python __init__( self, @@ -89,6 +87,7 @@ You can set and get the following properties: | master | App or Box | The container to which this widget belongs | | text_size | int | The size of the text | | text_color | [color](colors.md) | The colour of the text | +| tk | tkinter.Label | The internal tkinter object, see [Using tkinter](usingtk.md) | | value | string | The text | | visible | boolean | If this widget is visible | | width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | diff --git a/docs-src/docs/textbox.md b/docs-src/docs/textbox.md index 2a46a3d9..a1054810 100644 --- a/docs-src/docs/textbox.md +++ b/docs-src/docs/textbox.md @@ -1,7 +1,5 @@ # TextBox -(Contains a `tkinter.Entry` object) - ```python __init__( self, @@ -94,6 +92,7 @@ You can set and get the following properties: | width | [size](size.md) | Set the width of the widget in characters or to `"fill"` | | text_size | int | The size of the text | | text_color | [color](colors.md) | The colour of the text | +| tk | tkinter.Entry | The internal tkinter object, see [Using tkinter](usingtk.md) | ### Examples diff --git a/docs-src/docs/waffle.md b/docs-src/docs/waffle.md index 5e31ba3a..f4a94382 100644 --- a/docs-src/docs/waffle.md +++ b/docs-src/docs/waffle.md @@ -1,7 +1,5 @@ # Waffle -(Contains a `tkinter.Frame` object) - ```python __init__( self, @@ -41,21 +39,21 @@ app.display() When you create a `Waffle` object you **must** specify `master` and you can specify any of the optional parameters. Specify parameters in the brackets, like this: `waffle = Waffle(app, height=25)` -| Parameter | Takes | Default | Compulsory | Description | -|------------|--------------------|---------|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| master | App, Window or Box | - | Yes | The container to which this widget belongs | -| align | string | None | - | Alignment of this widget within its container. Possible values: `"top"`, `"bottom"`, `"left"`, `"right"`. | -| color | [color](colors.md) | "white" | - | The default colour of pixels on the waffle | -| command | function name | None | - | The name of a function to call when the waffle is clicked. This function MUST take either zero or two arguments, if the function takes two arguments the `x` and `y` co-ordinates of the pixel which was clicked will be given. | -| dim | int | 20 | - | How large one of the pixels on the waffle is | -| dotty | boolean | False | - | Whether the pixels display as dots/circles (True) or squares (False) | -| grid | List [int, int] | None | - | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid layout. | -| height | int | 3 | - | Set the height in waffle pixels | -| pad | int | 5 | - | How much space is between the pixels on the waffle | -| width | int | 3 | - | Set the width in waffle pixels | -| visible | boolean | True | No | If the widget should be visible. | -| enabled | boolean | None | No | If the widget should be enabled. If `None` (the default) the enabled property will be inherited from the master | -| bg | [color](colors.md) | None | No | The background colour of the waffle. Takes a [color](colors.md) value. | +| Parameter | Takes | Default | Compulsory | Description | +|-----------|--------------------|---------|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| master | App, Window or Box | - | Yes | The container to which this widget belongs | +| align | string | None | - | Alignment of this widget within its container. Possible values: `"top"`, `"bottom"`, `"left"`, `"right"`. | +| color | [color](colors.md) | "white" | - | The default colour of pixels on the waffle | +| command | function name | None | - | The name of a function to call when the waffle is clicked. This function MUST take either zero or two arguments, if the function takes two arguments the `x` and `y` co-ordinates of the pixel which was clicked will be given. | +| dim | int | 20 | - | How large one of the pixels on the waffle is | +| dotty | boolean | False | - | Whether the pixels display as dots/circles (True) or squares (False) | +| grid | List [int, int] | None | - | `[x,y]` coordinates of this widget. This parameter is only required if the `master` object has a grid layout. | +| height | int | 3 | - | Set the height in waffle pixels | +| pad | int | 5 | - | How much space is between the pixels on the waffle | +| width | int | 3 | - | Set the width in waffle pixels | +| visible | boolean | True | No | If the widget should be visible. | +| enabled | boolean | None | No | If the widget should be enabled. If `None` (the default) the enabled property will be inherited from the master | +| bg | [color](colors.md) | None | No | The background colour of the waffle. Takes a [color](colors.md) value. | ### Methods @@ -96,6 +94,7 @@ You can set and get the following properties: | master | App or Box | The container to which this widget belongs | | pad | int | The size of the padding between pixels | | pixel_size | int | The size of the one pixel | +| tk | tkinter.Frame | The internal tkinter object, see [Using tkinter](usingtk.md) | | width | [size](size.md) | Set the width in waffle pixels | | visible | boolean | If this widget is visible | diff --git a/docs-src/docs/window.md b/docs-src/docs/window.md index 4e67c9a3..b9f88959 100644 --- a/docs-src/docs/window.md +++ b/docs-src/docs/window.md @@ -1,7 +1,5 @@ # Window -(Contains a `tkinter.TopLevel` object) - ```python __init__( self, @@ -80,7 +78,7 @@ You can set and get the following properties: | Method | Data type | Description | |-------------|--------------------|-----------------------------------------------------------------------------------------------| | bg | [color](colors.md) | The background colour of the window | -| children | list(widgets) | A list of widgets in this container | +| children | List | A list of widgets in this container | | enabled | boolean | `True` if the window is enabled | | font | string | The font that widgets should use | | full_screen | boolean | False | @@ -89,6 +87,7 @@ You can set and get the following properties: | title | string | The title of the window | | text_size | int | The size of the text widgets should use | | text_color | [color](colors.md) | The colour of the text widgets should use | +| tk | tkinter.TopLevel | The internal tkinter object, see [Using tkinter](usingtk.md) | | visible | boolean | If the window is visible | | width | int | The width of the window | | when_closed | function | The function to call when the `Window` is closed. Setting to `None` (the default) will reset. | diff --git a/guizero/ListBox.py b/guizero/ListBox.py index 8fdf7add..dc59692f 100644 --- a/guizero/ListBox.py +++ b/guizero/ListBox.py @@ -76,7 +76,7 @@ def __init__( if scrollbar: # create the scrollbar and add it to the listbox scrollbar_tk_widget = Scrollbar(tk) - Widget(self, scrollbar_tk_widget, None, "right", True, True, None, "fill") + ListBoxScrollbar(self, scrollbar_tk_widget, None, "right", True, True, None, "fill") self._listbox.tk.config(yscrollcommand=scrollbar_tk_widget.set) scrollbar_tk_widget.config(command=self._listbox.tk.yview) @@ -254,3 +254,7 @@ def update_command(self, command): self._command = lambda: None else: self._command = command + + +class ListBoxScrollbar(Widget): + pass \ No newline at end of file From 2dea5ae75c6bcab00462b40578b0f75c0f6eec23 Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Fri, 27 Nov 2020 11:05:02 +0000 Subject: [PATCH 09/12] removed app.bgcolor --- docs-src/docs/changelog.md | 8 ++++++++ guizero/App.py | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs-src/docs/changelog.md b/docs-src/docs/changelog.md index cc94cc0b..1874adab 100644 --- a/docs-src/docs/changelog.md +++ b/docs-src/docs/changelog.md @@ -1,5 +1,13 @@ # guizero +## 1.1.1 - tbc +- PushButton image bug fix for macOS +- Documentation updates regarding how to use tk, particularly for ListBox widget +- Refactored `.description` property due to issue with TextBox widget +- Fix TextBox widget where you cant set the value if its disabled +- Removed `bgcolor` from App constructor which had previously been deprecated +- + ## 1.1.0 - 2019-10-25 - Added ability to be able to change the grid of a widget at room time - Added `hide_text` to `TextBox` for use with passwords diff --git a/guizero/App.py b/guizero/App.py index 1cd6ecbb..2454e69c 100644 --- a/guizero/App.py +++ b/guizero/App.py @@ -13,7 +13,6 @@ def __init__( width=500, height=500, layout="auto", - bgcolor=None, bg=None, visible=True): @@ -32,9 +31,6 @@ def __init__( :param string layout: The layout manager style for this window, defaults to `auto`. - :param string bgcolor: - DEPRECATED: The background colour for this window, defaults to None. Use bg instead. - :param color bg: The background colour for this window, defaults to None. See https://lawsie.github.io/guizero/colors/ From 923c1e55ed44f35d57dd4b581e099ee26934bd6c Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Fri, 27 Nov 2020 11:08:49 +0000 Subject: [PATCH 10/12] update Callable in docstrings --- guizero/ButtonGroup.py | 4 ++-- guizero/CheckBox.py | 4 ++-- guizero/Combo.py | 4 ++-- guizero/ListBox.py | 4 ++-- guizero/PushButton.py | 2 +- guizero/utilities.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/guizero/ButtonGroup.py b/guizero/ButtonGroup.py index 6423da15..e93ef234 100644 --- a/guizero/ButtonGroup.py +++ b/guizero/ButtonGroup.py @@ -39,7 +39,7 @@ def __init__( If the ButtonGroup is to be displayed horizontally, defaults to `True`. - :param callback command: + :param Callable command: The callback function to call when the ButtonGroup changes, defaults to `None`. @@ -299,7 +299,7 @@ def update_command(self, command, args=None): Setting to `None` stops the callback. - :param callback command: + :param Callable command: The callback function to call. :param callback args: diff --git a/guizero/CheckBox.py b/guizero/CheckBox.py index d660b555..730a687c 100644 --- a/guizero/CheckBox.py +++ b/guizero/CheckBox.py @@ -25,7 +25,7 @@ def __init__( :param string selected: The text required for the checkbox. Defaults to "". - :param callback command: + :param Callable command: The callback function to call when the CheckBox changes. :param List grid: @@ -123,7 +123,7 @@ def update_command(self, command, args=None): Setting to `None` stops the callback. - :param callback command: + :param Callable command: The callback function to call. :param args list: diff --git a/guizero/Combo.py b/guizero/Combo.py index 62a87a15..8ff58a85 100644 --- a/guizero/Combo.py +++ b/guizero/Combo.py @@ -40,7 +40,7 @@ def __init__( :param string selected: The item in the Combo to select, defaults to `None`. - :param callback command: + :param Callable command: The callback function to call when the Combo changes, defaults to `None`. @@ -311,7 +311,7 @@ def update_command(self, command): Setting to `None` stops the callback. - :param callback command: + :param Callable command: The callback function to call, it can accept 0 or 1 parameters. If it accepts 1 parameter the `value` of the Combo will be diff --git a/guizero/ListBox.py b/guizero/ListBox.py index dc59692f..e9113d2a 100644 --- a/guizero/ListBox.py +++ b/guizero/ListBox.py @@ -32,7 +32,7 @@ def __init__( :param string selected: The item in the ListBox to select, defaults to `None`. - :param callback command: + :param Callable command: The callback function to call when the ListBox changes, defaults to `None`. @@ -159,7 +159,7 @@ def update_command(self, command): Setting to `None` stops the callback. - :param callback command: + :param Callable command: The callback function to call, it can accept 0 or 1 parameters. If it accepts 1 parameter the `value` of the ListBox will be diff --git a/guizero/PushButton.py b/guizero/PushButton.py index 861c6a17..202b0b9e 100644 --- a/guizero/PushButton.py +++ b/guizero/PushButton.py @@ -26,7 +26,7 @@ def __init__( :param Container master: The Container (App, Box, etc) the Picture will belong to. - :param function command: + :param Callable command: A string containing the image to display, defaults to `None`. :param List args: diff --git a/guizero/utilities.py b/guizero/utilities.py index 5073e843..1daeab47 100644 --- a/guizero/utilities.py +++ b/guizero/utilities.py @@ -262,7 +262,7 @@ def __init__(self, master, guizero_image, update_image_callback): :param GUIZeroImage guizero_image: The image object which contains the animation. - :param function update_image_callback: + :param Callable update_image_callback: A function which should be called when the Image needs updating. The function will be called and passed a reference to the next Tk PhotoImage object in the animation. From 414649fad8ed5d172de33aa51d95e042ad9c0150 Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Fri, 27 Nov 2020 11:40:21 +0000 Subject: [PATCH 11/12] resolve tests --- tests/test_waffle.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_waffle.py b/tests/test_waffle.py index 679ee094..b7a11ad7 100644 --- a/tests/test_waffle.py +++ b/tests/test_waffle.py @@ -224,9 +224,10 @@ def mock_waffle_clicked(w): ev = MagicMock() ev.widget = w ev.tk_event.widget = w._canvas - ev.tk_event.x = 1 - # make sure the y is 1 pixel down - ev.tk_event.y = 1 + w.pixel_size + w.pad + # the x event occurs in the middle of the first pixel + ev.tk_event.x = ((w.pixel_size + w.pad) / 2) + # the y event occurs in the middle of the second pixel + ev.tk_event.y = 1 + (w.pixel_size + w.pad) + ((w.pixel_size + w.pad) / 2) w._clicked_on(ev) def test_after_schedule(): From 4f6dac6d36c9dc59e336e71ada088cee74179649 Mon Sep 17 00:00:00 2001 From: Martin O'Hanlon Date: Fri, 27 Nov 2020 11:50:16 +0000 Subject: [PATCH 12/12] v1.1.1 --- docs-src/docs/about.md | 2 +- docs-src/docs/changelog.md | 5 ++- docs-src/docs/index.md | 2 +- docs/about/index.html | 5 ++- docs/alerts/index.html | 35 +++++++++------ docs/app/index.html | 20 ++++++--- docs/blocking/index.html | 8 ++-- docs/box/index.html | 20 ++++++--- docs/buttongroup/index.html | 32 ++++++++++++-- docs/changelog/index.html | 12 ++++++ docs/checkbox/index.html | 18 +++++--- docs/colors/index.html | 6 ++- docs/combo/index.html | 15 +++++-- docs/commands/index.html | 2 +- docs/deployment/index.html | 5 +++ docs/development/index.html | 9 ++++ docs/drawing/index.html | 15 +++++-- docs/events/index.html | 8 ++-- docs/images/index.html | 6 ++- docs/index.html | 6 +-- docs/layout/index.html | 48 ++++++++++++++------- docs/listbox/index.html | 58 ++++++++++++++++++++++--- docs/menubar/index.html | 15 +++++-- docs/multiple_windows/index.html | 11 +++-- docs/picture/index.html | 15 +++++-- docs/pushbutton/index.html | 15 +++++-- docs/recipes/index.html | 20 ++++++--- docs/search/main.js | 4 +- docs/search/search_index.json | 2 +- docs/search/worker.js | 2 - docs/sitemap.xml | 72 +++++++++++++++---------------- docs/sitemap.xml.gz | Bin 214 -> 215 bytes docs/size/index.html | 3 +- docs/slider/index.html | 14 ++++-- docs/start/index.html | 12 ++++-- docs/text/index.html | 12 ++++-- docs/textbox/index.html | 23 +++++++--- docs/usingtk/index.html | 8 ++-- docs/waffle/index.html | 18 +++++--- docs/widgetoverview/index.html | 42 ++++++++++++------ docs/window/index.html | 22 +++++++--- guizero/__init__.py | 2 +- 42 files changed, 453 insertions(+), 196 deletions(-) diff --git a/docs-src/docs/about.md b/docs-src/docs/about.md index 13034150..2ec9fd9e 100644 --- a/docs-src/docs/about.md +++ b/docs-src/docs/about.md @@ -32,5 +32,5 @@ The aim of guizero is to make the process of creating simple GUIs quick, accessi ### Version -guizero is currently [version 1.1.0](changelog.md) +guizero is currently [version 1.1.1](changelog.md) diff --git a/docs-src/docs/changelog.md b/docs-src/docs/changelog.md index 1874adab..cf61ada1 100644 --- a/docs-src/docs/changelog.md +++ b/docs-src/docs/changelog.md @@ -1,12 +1,13 @@ # guizero -## 1.1.1 - tbc +## 1.1.1 - 2020-11-27 - PushButton image bug fix for macOS - Documentation updates regarding how to use tk, particularly for ListBox widget - Refactored `.description` property due to issue with TextBox widget - Fix TextBox widget where you cant set the value if its disabled - Removed `bgcolor` from App constructor which had previously been deprecated -- +- Resolved issue with `Waffle` and being able to click "outside" the waffle +- contributors [martinohanlon](https://github.com/martinohanlon), [aajshaw](https://github.com/aajshaw) ## 1.1.0 - 2019-10-25 - Added ability to be able to change the grid of a widget at room time diff --git a/docs-src/docs/index.md b/docs-src/docs/index.md index 722b0cf8..f85e1acc 100644 --- a/docs-src/docs/index.md +++ b/docs-src/docs/index.md @@ -142,7 +142,7 @@ If you installed guizero using the easy install method, to upgrade you should fo If you are using Windows you can install guizero by downloading and running a Windows MSI installer application. -1. Download either the [64-bit guizero installer](https://github.com/lawsie/guizero/releases/latest/download/guizero-1.1.0.amd64.msi) or the [32-bit guizero installer](https://github.com/lawsie/guizero/releases/latest/download/guizero-1.1.0.win32.msi) depending on which version of Python you are using. +1. Download either the [64-bit guizero installer](https://github.com/lawsie/guizero/releases/latest/download/guizero-1.1.1.amd64.msi) or the [32-bit guizero installer](https://github.com/lawsie/guizero/releases/latest/download/guizero-1.1.1.win32.msi) depending on which version of Python you are using. **Note:** If you are not sure what version of python you are running, run the following program in Python, which will output either `32` or `64`: diff --git a/docs/about/index.html b/docs/about/index.html index 0ea46128..7dd3cb49 100644 --- a/docs/about/index.html +++ b/docs/about/index.html @@ -356,7 +356,7 @@

What is guizero?

guizero is a Python 3 library for creating simple GUIs.

It is designed to allow new learners to quickly and easily create GUIs for their programs.

So have a go with guizero and see what you can create

-
from guizero import App, Text, PushButton
+
from guizero import App, Text, PushButton
 
 app = App(title="guizero")
 
@@ -365,6 +365,7 @@ 

What is guizero?

app.display()
+

Aims

The aim of guizero is to make the process of creating simple GUIs quick, accessible and understandable for new learners.

    @@ -376,7 +377,7 @@

    Aims

  • Generates helpful additional error messages

Version

-

guizero is currently version 1.1.0

+

guizero is currently version 1.1.1

diff --git a/docs/alerts/index.html b/docs/alerts/index.html index 80cdc49f..837f7129 100644 --- a/docs/alerts/index.html +++ b/docs/alerts/index.html @@ -356,12 +356,14 @@

Pop-ups

Alert popup

Using pop-ups

Pop-ups can be called from an App or Window object, for example:

-
app.info("info", "this is a guizero app")
+
app.info("info", "this is a guizero app")
 
+

Pop-ups can also be imported individually at the start of your program, for example:

-
from guizero import info
+
from guizero import info
 info("info", "this is a guizero app")
 
+

Purpose

These functions pop up a box on the screen that displays a message or asks a question. The functions available are:

    @@ -377,11 +379,12 @@

    Purpose

    Examples

    Warning box

    This will pop up a warning box with the title "Uh oh!" and the message "You are almost out of biscuits!".

    -
    from guizero import App
    +
    from guizero import App
     app = App(title="Biscuit monitor")
     app.warn("Uh oh!", "You are almost out of biscuits!")
     app.display()
     
    +

    On Windows, the box looks like this:

    Warning popup

    The info and error boxes work in exactly the same way but will display different icons.

    @@ -392,7 +395,7 @@

    Examples

  • If No was pressed, return False

You can store this value in a variable and test it:

-
from guizero import App
+
from guizero import App
 app = App(title="Snowman")
 build_a_snowman = app.yesno("A question...", "Do you want to build a snowman?")
 if build_a_snowman == True:
@@ -401,6 +404,7 @@ 

Examples

app.error("Snowman", "Okay bye...") app.display()
+

This code will first display the yes/no box

Yes No popup

If Yes is pressed, an information box will be displayed:

@@ -409,11 +413,12 @@

Examples

Info popup

Example: Using an alert as a callback

You can also use these functions in a callback (when you have to provide a function for another widget to call). Here is an example with a PushButton which pops up an info box when it is pressed.

-
from guizero import App, PushButton, info
+
from guizero import App, PushButton, info
 app = App()
 button = PushButton(app, command=app.info, args=["Info", "You pressed the button"])
 app.display()
 
+

The arguments provided to the PushButton are:

  • Where the button should be created (within the app)
  • @@ -422,7 +427,7 @@

    Examples

Example: Do you really want to close?

You can use a yesno box to check whether someone really wants to exit your app. If they click yes, the app is closed, if not, nothing happens and they can continue with what they were doing.

-
from guizero import App, Text
+
from guizero import App, Text
 
 # Ask the user if they really want to close the window
 def do_this_when_closed():
@@ -439,9 +444,10 @@ 

Examples

app.display()
+

Example: Asking a question

You can use a question pop-up to get information from the user. In this example the user is asked to enter their name when a button is pressed.

-
from guizero import App, PushButton, Text
+
from guizero import App, PushButton, Text
 
 def button_pressed():
     name = app.question("Hello", "What's your name?")
@@ -455,10 +461,11 @@ 

Examples

hello = Text(app) app.display()
+

question popu

Example: Get a file name

Ask the user to select a file using the select_file pop-up.

-
from guizero import App, PushButton, Text
+
from guizero import App, PushButton, Text
 
 def get_file():
     file_name.value = app.select_file()
@@ -470,17 +477,20 @@ 

Examples

app.display()
+

select file popup

You can change the file type filter by providing a list of type descriptions and extensions as the filetypes parameter e.g.

-
file_name.value = app.select_file(filetypes=[["All files", "*.*"], ["Text documents", "*.txt"]])
+
file_name.value = app.select_file(filetypes=[["All files", "*.*"], ["Text documents", "*.txt"]])
 
+

The default is to show an Open button, this can be changed to a Save button by setting the save parameter to True e.g.

-
file_name.value = app.select_file(save=True)
+
file_name.value = app.select_file(save=True)
 
+

select save file popup

Example: Get a folder name

Select a folder using the select_folder pop-up.

-
from guizero import App, PushButton, Text
+
from guizero import App, PushButton, Text
 
 def get_folder():
     path.value = app.select_folder()
@@ -492,9 +502,10 @@ 

Examples

app.display()
+

select folder popup

You can set the initial folder by passing a path to the folder parameter

-
file_name.value = app.select_file(folder="c:\users\lawsie")
+
file_name.value = app.select_file(folder="c:\users\lawsie")
 
diff --git a/docs/app/index.html b/docs/app/index.html index fcd0c786..44bf6cc0 100644 --- a/docs/app/index.html +++ b/docs/app/index.html @@ -358,8 +358,7 @@

App

-

(Contains a tkinter.Tk object)

-
__init__(
+
__init__(
     self, 
     title="guizero", 
     width=500, 
@@ -369,15 +368,17 @@ 

App

bg=None, visible=True)
+

What is it?

The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets.

App

How do I make one?

Create an App object like this:

-
from guizero import App
+
from guizero import App
 app = App()
 app.display()
 
+

Starting parameters

When you create an App object you can specify any of the following parameters, all of which are optional. Specify parameters in the brackets like this: app = App(bg="red", height=200)

@@ -600,7 +601,7 @@

Properties

- + @@ -644,6 +645,11 @@

Properties

+ + + + + @@ -666,17 +672,19 @@

Examples

Creating an App object

Create an App object by calling the App() constructor. You should give the object a name so you can refer to it later - in this case we have called it app. It is best to keep the name you give to your App object quite short, as you will have to use it to tell other widgets where they should be stored.

At the end of the program you MUST tell the app object to begin the display loop.

-
from guizero import App
+
from guizero import App
 app = App(title="My app", height=300, width=200)
 app.display()
 
+

Changing the title

You can change the title of the app object once it has been created like this:

-
from guizero import App
+
from guizero import App
 app = App(title="My app", height=300, width=200)
 app.title = "A different title"
 app.display()
 
+

This will display the app with the updated title:

App title

diff --git a/docs/blocking/index.html b/docs/blocking/index.html index d0bffef8..a2568059 100644 --- a/docs/blocking/index.html +++ b/docs/blocking/index.html @@ -352,14 +352,15 @@

Loops and sleeping

You may be used to writing programs which contain loops or make use of the sleep() command, but find when you try to use these with guizero they cause your GUI to freeze. This is because guizero (in common with almost all GUIs) operates an event driven model of programming which may be different to the one you are familiar with.

Your first guizero program might look a bit like this:

-
from guizero import App
+
from guizero import App
 app = App("Hello world")
 app.display()
 
+

The line of code app.display() doesn't just display the app - it enters an infinite event loop which is watching and waiting for events to happen on the GUI. Events include things like the user clicking on a button, moving a slider, typing in a text box etc. No code written after this line will ever execute because the event loop is infinite.

Example

Suppose you want a counter on your GUI to start counting up by 1 every second. You might be tempted to write a program like this:

-
from guizero import App, Text
+
from guizero import App, Text
 from time import sleep
 
 app = App("Hello world")
@@ -369,6 +370,7 @@ 

Example

sleep(1) app.display()
+

If you run this program, you'll see that this does not have the desired effect - your program crashes! This is because you have blocked the updating of your GUI in two ways:

  1. @@ -389,7 +391,7 @@

    Solution

    Set a callback to that function. You can either schedule the same callback to occur repeatedly after a given number of milliseconds (in this example 1000), or you can schedule it only once.

-
from guizero import App, Text
+
from guizero import App, Text
 
 # Action you would like to perform
 def counter():
diff --git a/docs/box/index.html b/docs/box/index.html
index 4d533b9b..75776da7 100644
--- a/docs/box/index.html
+++ b/docs/box/index.html
@@ -358,8 +358,7 @@
         

Box

-

(Contains a tkinter.Frame object)

-
__init__(
+
__init__(
     self,
     master,
     layout="auto",
@@ -371,16 +370,18 @@ 

Box

height=None, border=None)
+

What is it?

The Box object is an invisible container which can contain other widgets. It is the only object other than App and Window which can act as the master for other objects and can have its own layout manager.

You can use the Box object to group other objects within your GUI.

How do I make one?

Create a Box object like this:

-
from guizero import App, Box
+
from guizero import App, Box
 app = App()
 box = Box(app)
 app.display()
 
+

Starting parameters

When you create a Box object you must specify a master, and you can specify any of the optional parameters. Specify parameters in the brackets like this: box = Box(app, layout="grid")

childrenlist(widgets)List A list of widgets in this container
The colour of the text widgets should use
tktkinter.TkThe internal tkinter object, see Using tkinter
visible boolean If the app is visible
@@ -573,7 +574,7 @@

Properties

- + @@ -617,6 +618,11 @@

Properties

+ + + + + @@ -631,18 +637,19 @@

Properties

Examples

Putting widgets in a Box

A Box object is invisible, but it can contain other widgets. In this example, there are two Text objects. One has box as its master, the other has app as its master.

-
from guizero import App, Box, Text
+
from guizero import App, Box, Text
 app = App(title="My app", height=300, width=400)
 box = Box(app)
 text1 = Text(box, text="Hello from the box", size=14, text_color="red", font="Arial")
 text2 = Text(app, text="Hello from the app", size=14, text_color="blue", font="Courier New")
 app.display()
 
+

Box and app

Grouping objects within a Box

It is useful to put objects in a box to group them together. For example here we have given the app a grid layout, then placed some text at [0,0] and the Box object at [1,0]. This means that the text will appear on the left, and the contents of the Box will appear on the right.

The Box object itself has a grid layout and contains six buttons which are positioned on a separate grid layout belonging to the box.

-
from guizero import App, Text, Box, PushButton
+
from guizero import App, Text, Box, PushButton
 def do_nothing():
     return 0
 
@@ -658,6 +665,7 @@ 

Examples

app.display()
+

Box with grid layout

diff --git a/docs/buttongroup/index.html b/docs/buttongroup/index.html index 8bcb122c..6c64b0af 100644 --- a/docs/buttongroup/index.html +++ b/docs/buttongroup/index.html @@ -353,13 +353,14 @@
  • Examples
  • +
  • Using ButtonGroup tk widgets
  • +

    ButtonGroup

    -

    (Contains a tkinter.Frame object)

    -
    __init__(
    +
    __init__(
         self,
         master,
         options=[],
    @@ -374,16 +375,18 @@ 

    ButtonGroup

    width=None, height=None)
    +

    What is it?

    The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option.

    ButtonGroup

    How do I make one?

    Create a ButtonGroup object like this:

    -
    from guizero import App, ButtonGroup
    +
    from guizero import App, ButtonGroup
     app = App()
     choice = ButtonGroup(app, options=["cheese", "ham", "salad"], selected="cheese")
     app.display()
     
    +

    Starting parameters

    When you create a ButtonGroup object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets like this: choice = ButtonGroup(app, options=["cheese", "ham", "salad"], selected=1)

    childrenlist(widgets)List A list of widgets in this container
    The colour of the text widgets should use
    tktkinter.FrameThe internal tkinter object, see Using tkinter
    visible boolean If this widget is visible
    @@ -609,6 +612,11 @@

    Properties

    + + + + + @@ -663,6 +671,11 @@

    Properties

    + + + + +
    The background colour of the widget
    childrenListA list of the widgets in this container. [RadioButton, *]
    enabled boolean True if the widget is enabledcolor The colour of the text
    tktkinter.FrameThe internal tkinter object, see Using tkinter

    Refer to a property as <name of widget>.property. For example, if your ButtonGroup object is called choice you would write choice.value.

    @@ -670,7 +683,7 @@

    Properties

    Examples

    Creating a ButtonGroup with a 2D list

    If you want to create a ButtonGroup object with your own hidden values you can specify a 2D list of options:

    -
    from guizero import App, ButtonGroup, Text
    +
    from guizero import App, ButtonGroup, Text
     
     def update_text():
         what_is_selected.value = activities.value
    @@ -685,6 +698,17 @@ 

    Examples

    what_is_selected = Text(app, text="skate") app.display() +
    + +

    Using ButtonGroup tk widgets

    +

    Advanced users can gain internal access to the internal tkinter widgets used by ButtonGroup. For more information on using tkinter in combination with guizero see Using tkinter.

    +

    The ButtonGroup widget contains a tkinter.Frame object, which frames multiple guizero RadioButton widgets. Each RadioButton widget contains a tkinter.Radiobutton object.

    +

    The .children property returns the list of RadioButton widgets in the order they appear in the ButtonGroup:

    +

    To access the internal RadioButton tk object you would use the child's tk property e.g.

    +
    button_group = ButtonGroup(app)
    +
    +for radio_button in ButtonGroup.children:
    +    tk_radio_button = radio_button.tk
     
    diff --git a/docs/changelog/index.html b/docs/changelog/index.html index 86064c88..7221254a 100644 --- a/docs/changelog/index.html +++ b/docs/changelog/index.html @@ -341,6 +341,8 @@
    diff --git a/docs/menubar/index.html b/docs/menubar/index.html index 73dd7364..5d813f63 100644 --- a/docs/menubar/index.html +++ b/docs/menubar/index.html @@ -356,19 +356,19 @@

    MenuBar

    -

    (Contains a tkinter.Menu object)

    -
    __init__(
    +
    __init__(
         self, 
         master, 
         toplevel, 
         options)
     
    +

    What is it?

    The MenuBar object displays a menu at the top of the screen, with each menu option leading to a submenu.

    MenuBar on Windows

    How do I make one?

    Create a MenuBar object like this:

    -
    from guizero import App, MenuBar
    +
    from guizero import App, MenuBar
     def file_function():
         print("File option")
     
    @@ -384,6 +384,7 @@ 

    How do I make one?

    ]) app.display()
    +

    Starting parameters

    When you create a MenuBar object you must specify all of the parameters.

    @@ -424,8 +425,9 @@

    Starting parameters

    Top level menu on Windows

    The options parameter should be a 3D List containing lists of submenu items, which are themselves lists. The elements in the list correspond to the elements in the toplevel list, so the first list of submenu items provided in options will be the submenu for the first menu heading provided in toplevel and so on.

    The menu item sub-sublists within options should contain pairs consisting of the text to display on the menu and the function to call when that option is selected. In this example, the text "File option 1" is displayed and the function file_function is called if this option is clicked on.

    -
    ["File option 1", file_function]
    +
    ["File option 1", file_function]
     
    +

    The MenuBar is never displayed on a grid so there are no grid or alignment parameters.

    Methods

    You can call the following methods on an MenuBar object.

    @@ -487,6 +489,11 @@

    Properties

    + + + + +
    App The App object to which this MenuBar belongs
    tktkinter.MenuThe internal tkinter object, see Using tkinter
    diff --git a/docs/multiple_windows/index.html b/docs/multiple_windows/index.html index 478dc543..cd9c8d7c 100644 --- a/docs/multiple_windows/index.html +++ b/docs/multiple_windows/index.html @@ -356,7 +356,7 @@

    Multiple Windows

    If you want to create a second (or 3rd, 4th, 5th) window, your program should use a Window object.

    A Second window

    When you create a second Window you need to pass it the App, just like when you create a widget:

    -
    from guizero import App, Window
    +
    from guizero import App, Window
     
     app = App(title="Main window")
     window = Window(app, title="Second window")
    @@ -364,8 +364,9 @@ 

    A Second window

    app.display()
    +

    Adding widgets to the second window is the same as adding them to an App. You tell the widget which window it will be in by passing it the name of the Window:

    -
    from guizero import App, Window, Text
    +
    from guizero import App, Window, Text
     
     app = App(title="Main window")
     window = Window(app, title="Second window")
    @@ -374,10 +375,11 @@ 

    A Second window

    app.display()
    +

    Opening and closing windows

    When a Window object is created it is immediately displayed on the screen. You can control whether a window is visible or not using the show() and hide() methods.

    This code creates a window which is shown when a button on the App is clicked and closed when a button is clicked in the Window.

    -
    from guizero import App, Window, PushButton
    +
    from guizero import App, Window, PushButton
     
     def open_window():
         window.show()
    @@ -395,11 +397,12 @@ 

    Opening and closing windows

    app.display()
    +

    When a window is opened using show() it opens side by side with the main window, and both windows can be used at the same time.

    A "modal" window prevents the other windows in the application being used until it is closed. To create a modal window, you can pass True to the optional wait parameter of show.

    This will force all other windows to wait until this window is closed before they can be used.

    -
    def open_window():
    +
    def open_window():
         window.show(wait=True)
     
    diff --git a/docs/picture/index.html b/docs/picture/index.html index 3136dba7..e956ad01 100644 --- a/docs/picture/index.html +++ b/docs/picture/index.html @@ -358,8 +358,7 @@

    Picture

    -

    (Contains a tkinter.Label object)

    -
    __init__(
    +
    __init__(
         self, 
         master, 
         image=None, 
    @@ -370,19 +369,22 @@ 

    Picture

    width=None, height=None)
    +

    What is it?

    The Picture object displays an image.

    Picture on Windows

    How do I make one?

    Create a Picture object like this:

    -
    from guizero import App, Picture
    +
    from guizero import App, Picture
     app = App()
     picture = Picture(app, image="test.gif")
     app.display()
     
    +

    You must specify the correct path to the image. The image in the example is in the same directory as the program. If the image is in a different directory, specify a relative path, for example if the picture is in a subfolder called images you would write:

    -
    picture = Picture(app, image="images/test.gif")
    +
    picture = Picture(app, image="images/test.gif")
     
    +

    Image support

    Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use with Picture.

    By default GIF and PNG are supported, except macOS which only supports GIF.

    @@ -578,6 +580,11 @@

    Properties

    The container to which this widget belongs +tk +tkinter.Label +The internal tkinter object, see Using tkinter + + value string The file path, tkinter.PhotoImage or PIL.Image you wish to display diff --git a/docs/pushbutton/index.html b/docs/pushbutton/index.html index 41ac21c4..24388adb 100644 --- a/docs/pushbutton/index.html +++ b/docs/pushbutton/index.html @@ -356,8 +356,7 @@

    PushButton

    -

    (Contains a tkinter.Button object)

    -
    __init__(
    +
    __init__(
         self,
         master,
         command=None,
    @@ -374,12 +373,13 @@ 

    PushButton

    width=None, height=None)
    +

    What is it?

    The PushButton object displays a button with text or an image, which calls a function when pressed.

    PushButton on Windows

    How do I make one?

    Create a PushButton object like this:

    -
    from guizero import App, PushButton
    +
    from guizero import App, PushButton
     def do_nothing():
         print("Button was pressed")
     
    @@ -387,8 +387,9 @@ 

    How do I make one?

    button = PushButton(app, command=do_nothing) app.display()
    +

    Create a picture PushButton with an image like this:

    -
    from guizero import App, PushButton
    +
    from guizero import App, PushButton
     def do_nothing():
         print("A picture button was pressed")
     
    @@ -396,6 +397,7 @@ 

    How do I make one?

    button = PushButton(app, image="button.gif", command=do_nothing) app.display()
    +

    Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use for PushButton. By default GIF and PNG are supported, except macOS which only supports GIF.

    Starting parameters

    When you create a PushButton object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: button = PushButton(app)

    @@ -663,6 +665,11 @@

    Properties

    The size of the text on the button +tk +tkinter.Button +The internal tkinter object, see Using tkinter + + value int Returns 1 when the button is pressed, 0 if the button is released diff --git a/docs/recipes/index.html b/docs/recipes/index.html index d8675055..6181dc53 100644 --- a/docs/recipes/index.html +++ b/docs/recipes/index.html @@ -363,23 +363,25 @@

    Recipes

    These are examples of how you can use guizero to create user interfaces. Don't be restricted to these ideas, check out Using guizero and the widgets.

    Hello World

    Create a guizero app and display some text.

    -
    from guizero import App, Text
    +
    from guizero import App, Text
     app = App()
     text = Text(app, text="hello world")
     app.display()
     
    +

    Get some text

    Get some data from the user using a TextBox.

    -
    from guizero import App, TextBox
    +
    from guizero import App, TextBox
     
     app = App()
     name = TextBox(app, text="Enter your name")
     
     app.display()
     
    +

    Push a button

    Use a PushButton to display a message when the button is pressed.

    -
    from guizero import App, TextBox, PushButton, Text
    +
    from guizero import App, TextBox, PushButton, Text
     
     def update_text():
         label.value = name.value
    @@ -391,16 +393,18 @@ 

    Push a button

    app.display()
    +

    Display an image

    Use a Picture object to display an image.

    -
    from guizero import App, Picture
    +
    from guizero import App, Picture
     app = App()
     pic = Picture(app, image="myimage.gif")
     app.display()
     
    +

    Toggle 2 buttons

    Have 2 buttons, start and stop with them changing the enabled state of each other.

    -
    from guizero import App, PushButton
    +
    from guizero import App, PushButton
     
     def start():
         start_button.disable()
    @@ -415,9 +419,10 @@ 

    Toggle 2 buttons

    stop_button = PushButton(app, command=stop, text="stop", enabled=False) app.display()
    +

    Change your apps appearance

    Your app doesn't have to use the standard colors and text, let your user pick the background and text color from 2 combo's.

    -
    from guizero import App, Combo, Text
    +
    from guizero import App, Combo, Text
     
     def update_bg():
         app.bg = bg_combo.value
    @@ -439,9 +444,10 @@ 

    Change your apps appearance

    app.display()
    +

    Scale an image

    Display an image on the screen with 2 sliders, 1 for height and 1 for width.

    -
    from guizero import App, Slider, Picture
    +
    from guizero import App, Slider, Picture
     
     def resize():
         picture.width = width.value
    diff --git a/docs/search/main.js b/docs/search/main.js
    index 0e1fc811..0a82ab56 100644
    --- a/docs/search/main.js
    +++ b/docs/search/main.js
    @@ -43,7 +43,7 @@ function displayResults (results) {
     
     function doSearch () {
       var query = document.getElementById('mkdocs-search-query').value;
    -  if (query.length > min_search_length) {
    +  if (query.length > 2) {
         if (!window.Worker) {
           displayResults(search(query));
         } else {
    @@ -73,8 +73,6 @@ function onWorkerMessage (e) {
       } else if (e.data.results) {
         var results = e.data.results;
         displayResults(results);
    -  } else if (e.data.config) {
    -    min_search_length = e.data.config.min_search_length-1;
       }
     }
     
    diff --git a/docs/search/search_index.json b/docs/search/search_index.json
    index 99fc6efe..387b70a4 100644
    --- a/docs/search/search_index.json
    +++ b/docs/search/search_index.json
    @@ -1 +1 @@
    -{"config":{"lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Installation guizero is designed to allow new learners to quickly and easily create GUIs for their programs. If you can download and unzip a file, you can install guizero - no special permissions or administrator rights are required . If you have administrator rights and are connected to the internet, you can use pip to install or upgrade guizero (recommended). Windows users can also use the Windows MSI installer . Easy install Go to the guizero repository on GitHub. Click the green \"Code\" button and then \"Download ZIP\" Open the zip file Open the guizero-master folder, then copy the guizero folder and paste it into your home directory Windows macOS That's it! When you write your guizero code, make sure you save it into your home directory. Install using pip You can use the command prompt and pip to install guizero for: Windows macOS Raspberry Pi Linux pip can also be used to install additional features and upgrade guizero . Windows Open a command prompt by clicking Start > Windows System > Command Prompt , or by typing 'command' into the start menu's search bar. Type this command and press enter: pip3 install guizero If you experience problems, have a look at this guide to Using pip on Windows . macOS Open a terminal window by clicking Applications > Utilities > Terminal , or by typing 'terminal' into the desktop's search bar. Type this command and press enter: pip3 install guizero Raspberry Pi Open a terminal window by clicking Menu > Accessories > Terminal . Type this command and press enter: sudo pip3 install guizero Linux Open a terminal Install tkinter using your distribution's package manager, e.g. sudo apt install python3-tk Install guizero using pip by typing pip3 install guizero or sudo pip3 install guizero if you don't have superuser rights Note: If you are using Debian, you alternatively have the option to install guizero via apt sudo apt-get install python-guizero Install additional features To use the additional image features of guizero such as: JPG image support scaling images animated gifs ... you will need to install guizero with the pip command: Windows / macOS pip3 install guizero[images] Linux / Raspberry Pi sudo pip3 install guizero[images] The additional image features are not available to install using the easy install method. Upgrading guizero If you installed guizero using pip, you can upgrade guizero using a pip command: Windows / macOS pip3 install guizero --upgrade Linux / Raspberry Pi sudo pip3 install guizero --upgrade If you installed guizero using the easy install method, to upgrade you should follow the same easy installation steps to download the latest version of guizero, then delete the old guizero folder and replace it with the newest version. Windows MSI installer If you are using Windows you can install guizero by downloading and running a Windows MSI installer application. Download either the 64-bit guizero installer or the 32-bit guizero installer depending on which version of Python you are using. Note: If you are not sure what version of python you are running, run the following program in Python, which will output either 32 or 64 : import struct print(struct.calcsize(\"P\") * 8) Run the guizero installer and select whether guizero should be installed for all users or just for me and click Next . Select which version(s) of Python you want to install guizero for and click Next . Note: For most people, there will be only one version of Python and you can safely choose the default option. You may be asked \"Do you wish to allow this application from an unknown publisher to make changes to your device?\" - click Yes . Wait while guizero is installed. Click Finish when the installation is complete.","title":"Installation"},{"location":"#installation","text":"guizero is designed to allow new learners to quickly and easily create GUIs for their programs. If you can download and unzip a file, you can install guizero - no special permissions or administrator rights are required . If you have administrator rights and are connected to the internet, you can use pip to install or upgrade guizero (recommended). Windows users can also use the Windows MSI installer .","title":"Installation"},{"location":"#easy-install","text":"Go to the guizero repository on GitHub. Click the green \"Code\" button and then \"Download ZIP\" Open the zip file Open the guizero-master folder, then copy the guizero folder and paste it into your home directory Windows macOS That's it! When you write your guizero code, make sure you save it into your home directory.","title":"Easy install"},{"location":"#install-using-pip","text":"You can use the command prompt and pip to install guizero for: Windows macOS Raspberry Pi Linux pip can also be used to install additional features and upgrade guizero .","title":"Install using pip"},{"location":"#windows","text":"Open a command prompt by clicking Start > Windows System > Command Prompt , or by typing 'command' into the start menu's search bar. Type this command and press enter: pip3 install guizero If you experience problems, have a look at this guide to Using pip on Windows .","title":"Windows"},{"location":"#macos","text":"Open a terminal window by clicking Applications > Utilities > Terminal , or by typing 'terminal' into the desktop's search bar. Type this command and press enter: pip3 install guizero","title":"macOS"},{"location":"#raspberry-pi","text":"Open a terminal window by clicking Menu > Accessories > Terminal . Type this command and press enter: sudo pip3 install guizero","title":"Raspberry Pi"},{"location":"#linux","text":"Open a terminal Install tkinter using your distribution's package manager, e.g. sudo apt install python3-tk Install guizero using pip by typing pip3 install guizero or sudo pip3 install guizero if you don't have superuser rights Note: If you are using Debian, you alternatively have the option to install guizero via apt sudo apt-get install python-guizero","title":"Linux"},{"location":"#install-additional-features","text":"To use the additional image features of guizero such as: JPG image support scaling images animated gifs ... you will need to install guizero with the pip command: Windows / macOS pip3 install guizero[images] Linux / Raspberry Pi sudo pip3 install guizero[images] The additional image features are not available to install using the easy install method.","title":"Install additional features"},{"location":"#upgrading-guizero","text":"If you installed guizero using pip, you can upgrade guizero using a pip command: Windows / macOS pip3 install guizero --upgrade Linux / Raspberry Pi sudo pip3 install guizero --upgrade If you installed guizero using the easy install method, to upgrade you should follow the same easy installation steps to download the latest version of guizero, then delete the old guizero folder and replace it with the newest version.","title":"Upgrading guizero"},{"location":"#windows-msi-installer","text":"If you are using Windows you can install guizero by downloading and running a Windows MSI installer application. Download either the 64-bit guizero installer or the 32-bit guizero installer depending on which version of Python you are using. Note: If you are not sure what version of python you are running, run the following program in Python, which will output either 32 or 64 : import struct print(struct.calcsize(\"P\") * 8) Run the guizero installer and select whether guizero should be installed for all users or just for me and click Next . Select which version(s) of Python you want to install guizero for and click Next . Note: For most people, there will be only one version of Python and you can safely choose the default option. You may be asked \"Do you wish to allow this application from an unknown publisher to make changes to your device?\" - click Yes . Wait while guizero is installed. Click Finish when the installation is complete.","title":"Windows MSI installer"},{"location":"about/","text":"About What is guizero? guizero is a Python 3 library for creating simple GUIs. It is designed to allow new learners to quickly and easily create GUIs for their programs. from guizero import App, Text, PushButton app = App(title=\"guizero\") intro = Text(app, text=\"Have a go with guizero and see what you can create.\") ok = PushButton(app, text=\"Ok\") app.display() Aims The aim of guizero is to make the process of creating simple GUIs quick, accessible and understandable for new learners. Works with standard Python Tkinter GUI library (and no need to install other libraries) Abstracts away details new learners find difficult to understand (such as Tkinter StringVar() objects) Accessible widget naming system to help new learners to build up a mental model Flexible enough to be used for projects up to A-Level standard, yet accessible to primary school children Comprehensive and accessible documentation with examples Generates helpful additional error messages Version guizero is currently version 1.1.0","title":"About"},{"location":"about/#about","text":"","title":"About"},{"location":"about/#what-is-guizero","text":"guizero is a Python 3 library for creating simple GUIs. It is designed to allow new learners to quickly and easily create GUIs for their programs. from guizero import App, Text, PushButton app = App(title=\"guizero\") intro = Text(app, text=\"Have a go with guizero and see what you can create.\") ok = PushButton(app, text=\"Ok\") app.display()","title":"What is guizero?"},{"location":"about/#aims","text":"The aim of guizero is to make the process of creating simple GUIs quick, accessible and understandable for new learners. Works with standard Python Tkinter GUI library (and no need to install other libraries) Abstracts away details new learners find difficult to understand (such as Tkinter StringVar() objects) Accessible widget naming system to help new learners to build up a mental model Flexible enough to be used for projects up to A-Level standard, yet accessible to primary school children Comprehensive and accessible documentation with examples Generates helpful additional error messages","title":"Aims"},{"location":"about/#version","text":"guizero is currently version 1.1.0","title":"Version"},{"location":"alerts/","text":"Pop-ups Pop-up windows which can be used to interrupt the user by asking question or providing information. Using pop-ups Pop-ups can be called from an App or Window object, for example: app.info(\"info\", \"this is a guizero app\") Pop-ups can also be imported individually at the start of your program, for example: from guizero import info info(\"info\", \"this is a guizero app\") Purpose These functions pop up a box on the screen that displays a message or asks a question. The functions available are: warn(title, text) - popup box with a warning icon info(title, text) - popup box with an information icon error(title, text) - popup box with an error icon yesno(title, text) - popup box with yes and no options. Pressing Yes returns True and pressing No returns False . question(title, text, initial_value=None) - popup box with a question box which can accept a text response. Pressing Ok returns value entered into the box is returned and pressing Cancel returns None . select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \"*.*\"]], save=False) - popup file dialog box which asks the user to select a file. By default, an Open button is displayed, setting save to True will change the button to Save as . The path of the selected file is returned by the function. select_folder(title=\"Select folder\", folder=\".\") - popup box which asks the user to select a folder. The path of the selected folder is returned by the function. All pop up boxes use the native display, so they will look different depending on your operating system. Examples Warning box This will pop up a warning box with the title \"Uh oh!\" and the message \"You are almost out of biscuits!\" . from guizero import App app = App(title=\"Biscuit monitor\") app.warn(\"Uh oh!\", \"You are almost out of biscuits!\") app.display() On Windows, the box looks like this: The info and error boxes work in exactly the same way but will display different icons. Yes/No box When this function is called it returns a boolean value. If Yes was pressed, return True If No was pressed, return False You can store this value in a variable and test it: from guizero import App app = App(title=\"Snowman\") build_a_snowman = app.yesno(\"A question...\", \"Do you want to build a snowman?\") if build_a_snowman == True: app.info(\"Snowman\", \"It doesn't have to be a snowman\") else: app.error(\"Snowman\", \"Okay bye...\") app.display() This code will first display the yes/no box If Yes is pressed, an information box will be displayed: If No is pressed, an error box will be displayed Example: Using an alert as a callback You can also use these functions in a callback (when you have to provide a function for another widget to call). Here is an example with a PushButton which pops up an info box when it is pressed. from guizero import App, PushButton, info app = App() button = PushButton(app, command=app.info, args=[\"Info\", \"You pressed the button\"]) app.display() The arguments provided to the PushButton are: Where the button should be created (within the app ) The name of the function to call when pressed ( info ) A list of the arguments to the function you are calling (values for the title and message arguments for the info function) Example: Do you really want to close? You can use a yesno box to check whether someone really wants to exit your app. If they click yes, the app is closed, if not, nothing happens and they can continue with what they were doing. from guizero import App, Text # Ask the user if they really want to close the window def do_this_when_closed(): if app.yesno(\"Close\", \"Do you want to quit?\"): app.destroy() app = App() title = Text(app, text=\"blank app\") # When the user tries to close the window, run the function do_this_when_closed() app.when_closed = do_this_when_closed app.display() Example: Asking a question You can use a question pop-up to get information from the user. In this example the user is asked to enter their name when a button is pressed. from guizero import App, PushButton, Text def button_pressed(): name = app.question(\"Hello\", \"What's your name?\") # If cancel is pressed, None is returned # so check a name was entered if name is not None: hello.value = \"Hello \" + name app = App() button = PushButton(app, command=button_pressed, text=\"Hello\") hello = Text(app) app.display() Example: Get a file name Ask the user to select a file using the select_file pop-up. from guizero import App, PushButton, Text def get_file(): file_name.value = app.select_file() app = App() PushButton(app, command=get_file, text=\"Get file\") file_name = Text(app) app.display() You can change the file type filter by providing a list of type descriptions and extensions as the filetypes parameter e.g. file_name.value = app.select_file(filetypes=[[\"All files\", \"*.*\"], [\"Text documents\", \"*.txt\"]]) The default is to show an Open button, this can be changed to a Save button by setting the save parameter to True e.g. file_name.value = app.select_file(save=True) Example: Get a folder name Select a folder using the select_folder pop-up. from guizero import App, PushButton, Text def get_folder(): path.value = app.select_folder() app = App() PushButton(app, command=get_folder, text=\"Get path\") path = Text(app) app.display() You can set the initial folder by passing a path to the folder parameter file_name.value = app.select_file(folder=\"c:\\users\\lawsie\")","title":"Pop-ups"},{"location":"alerts/#pop-ups","text":"Pop-up windows which can be used to interrupt the user by asking question or providing information.","title":"Pop-ups"},{"location":"alerts/#using-pop-ups","text":"Pop-ups can be called from an App or Window object, for example: app.info(\"info\", \"this is a guizero app\") Pop-ups can also be imported individually at the start of your program, for example: from guizero import info info(\"info\", \"this is a guizero app\")","title":"Using pop-ups"},{"location":"alerts/#purpose","text":"These functions pop up a box on the screen that displays a message or asks a question. The functions available are: warn(title, text) - popup box with a warning icon info(title, text) - popup box with an information icon error(title, text) - popup box with an error icon yesno(title, text) - popup box with yes and no options. Pressing Yes returns True and pressing No returns False . question(title, text, initial_value=None) - popup box with a question box which can accept a text response. Pressing Ok returns value entered into the box is returned and pressing Cancel returns None . select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \"*.*\"]], save=False) - popup file dialog box which asks the user to select a file. By default, an Open button is displayed, setting save to True will change the button to Save as . The path of the selected file is returned by the function. select_folder(title=\"Select folder\", folder=\".\") - popup box which asks the user to select a folder. The path of the selected folder is returned by the function. All pop up boxes use the native display, so they will look different depending on your operating system.","title":"Purpose"},{"location":"alerts/#examples","text":"Warning box This will pop up a warning box with the title \"Uh oh!\" and the message \"You are almost out of biscuits!\" . from guizero import App app = App(title=\"Biscuit monitor\") app.warn(\"Uh oh!\", \"You are almost out of biscuits!\") app.display() On Windows, the box looks like this: The info and error boxes work in exactly the same way but will display different icons. Yes/No box When this function is called it returns a boolean value. If Yes was pressed, return True If No was pressed, return False You can store this value in a variable and test it: from guizero import App app = App(title=\"Snowman\") build_a_snowman = app.yesno(\"A question...\", \"Do you want to build a snowman?\") if build_a_snowman == True: app.info(\"Snowman\", \"It doesn't have to be a snowman\") else: app.error(\"Snowman\", \"Okay bye...\") app.display() This code will first display the yes/no box If Yes is pressed, an information box will be displayed: If No is pressed, an error box will be displayed Example: Using an alert as a callback You can also use these functions in a callback (when you have to provide a function for another widget to call). Here is an example with a PushButton which pops up an info box when it is pressed. from guizero import App, PushButton, info app = App() button = PushButton(app, command=app.info, args=[\"Info\", \"You pressed the button\"]) app.display() The arguments provided to the PushButton are: Where the button should be created (within the app ) The name of the function to call when pressed ( info ) A list of the arguments to the function you are calling (values for the title and message arguments for the info function) Example: Do you really want to close? You can use a yesno box to check whether someone really wants to exit your app. If they click yes, the app is closed, if not, nothing happens and they can continue with what they were doing. from guizero import App, Text # Ask the user if they really want to close the window def do_this_when_closed(): if app.yesno(\"Close\", \"Do you want to quit?\"): app.destroy() app = App() title = Text(app, text=\"blank app\") # When the user tries to close the window, run the function do_this_when_closed() app.when_closed = do_this_when_closed app.display() Example: Asking a question You can use a question pop-up to get information from the user. In this example the user is asked to enter their name when a button is pressed. from guizero import App, PushButton, Text def button_pressed(): name = app.question(\"Hello\", \"What's your name?\") # If cancel is pressed, None is returned # so check a name was entered if name is not None: hello.value = \"Hello \" + name app = App() button = PushButton(app, command=button_pressed, text=\"Hello\") hello = Text(app) app.display() Example: Get a file name Ask the user to select a file using the select_file pop-up. from guizero import App, PushButton, Text def get_file(): file_name.value = app.select_file() app = App() PushButton(app, command=get_file, text=\"Get file\") file_name = Text(app) app.display() You can change the file type filter by providing a list of type descriptions and extensions as the filetypes parameter e.g. file_name.value = app.select_file(filetypes=[[\"All files\", \"*.*\"], [\"Text documents\", \"*.txt\"]]) The default is to show an Open button, this can be changed to a Save button by setting the save parameter to True e.g. file_name.value = app.select_file(save=True) Example: Get a folder name Select a folder using the select_folder pop-up. from guizero import App, PushButton, Text def get_folder(): path.value = app.select_folder() app = App() PushButton(app, command=get_folder, text=\"Get path\") path = Text(app) app.display() You can set the initial folder by passing a path to the folder parameter file_name.value = app.select_file(folder=\"c:\\users\\lawsie\")","title":"Examples"},{"location":"app/","text":"App (Contains a tkinter.Tk object) __init__( self, title=\"guizero\", width=500, height=500, layout=\"auto\", bgcolor=None, bg=None, visible=True) What is it? The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets. How do I make one? Create an App object like this: from guizero import App app = App() app.display() Starting parameters When you create an App object you can specify any of the following parameters, all of which are optional. Specify parameters in the brackets like this: app = App(bg=\"red\", height=200) Parameter Data type Default Compulsory Description bg color None No The background colour of the app window and widgets inside it. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the App should be visible. Methods You can call the following methods on an App object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables all the widgets in the app so that they cannot be interacted with display() - - Displays the app on the screen. You MUST call this method at the end of your program to display the app on the screen. enable() - - Enables all the widgets in the app error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the widget hide() - - Hides the app window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show() - - Displays the app window if it was previously hidden update() - - Force the application to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window. Parameters in italics will still work but are deprecated - this means you should stop using them because they may not work in future versions of guizero Properties You can set and get the following properties: Method Data type Description bg color The background colour of the window children list(widgets) A list of widgets in this container enabled boolean True if the app is enabled height int The height of the window font string The font that widgets should use full_screen boolean False layout string The layout being used by the App ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use visible boolean If the app is visible width int The width of the window when_closed function The function to call when the App is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your App object is called app you would write app.title . You can set the property (for example app.title = \"Hello world\" ) or get the value of the property to use (for example print(app.title) ). Examples Creating an App object Create an App object by calling the App() constructor. You should give the object a name so you can refer to it later - in this case we have called it app . It is best to keep the name you give to your App object quite short, as you will have to use it to tell other widgets where they should be stored. At the end of the program you MUST tell the app object to begin the display loop. from guizero import App app = App(title=\"My app\", height=300, width=200) app.display() Changing the title You can change the title of the app object once it has been created like this: from guizero import App app = App(title=\"My app\", height=300, width=200) app.title = \"A different title\" app.display() This will display the app with the updated title:","title":"App"},{"location":"app/#app","text":"(Contains a tkinter.Tk object) __init__( self, title=\"guizero\", width=500, height=500, layout=\"auto\", bgcolor=None, bg=None, visible=True)","title":"App"},{"location":"app/#what-is-it","text":"The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets.","title":"What is it?"},{"location":"app/#how-do-i-make-one","text":"Create an App object like this: from guizero import App app = App() app.display()","title":"How do I make one?"},{"location":"app/#starting-parameters","text":"When you create an App object you can specify any of the following parameters, all of which are optional. Specify parameters in the brackets like this: app = App(bg=\"red\", height=200) Parameter Data type Default Compulsory Description bg color None No The background colour of the app window and widgets inside it. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the App should be visible.","title":"Starting parameters"},{"location":"app/#methods","text":"You can call the following methods on an App object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables all the widgets in the app so that they cannot be interacted with display() - - Displays the app on the screen. You MUST call this method at the end of your program to display the app on the screen. enable() - - Enables all the widgets in the app error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the widget hide() - - Hides the app window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show() - - Displays the app window if it was previously hidden update() - - Force the application to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window. Parameters in italics will still work but are deprecated - this means you should stop using them because they may not work in future versions of guizero","title":"Methods"},{"location":"app/#properties","text":"You can set and get the following properties: Method Data type Description bg color The background colour of the window children list(widgets) A list of widgets in this container enabled boolean True if the app is enabled height int The height of the window font string The font that widgets should use full_screen boolean False layout string The layout being used by the App ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use visible boolean If the app is visible width int The width of the window when_closed function The function to call when the App is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your App object is called app you would write app.title . You can set the property (for example app.title = \"Hello world\" ) or get the value of the property to use (for example print(app.title) ).","title":"Properties"},{"location":"app/#examples","text":"Creating an App object Create an App object by calling the App() constructor. You should give the object a name so you can refer to it later - in this case we have called it app . It is best to keep the name you give to your App object quite short, as you will have to use it to tell other widgets where they should be stored. At the end of the program you MUST tell the app object to begin the display loop. from guizero import App app = App(title=\"My app\", height=300, width=200) app.display() Changing the title You can change the title of the app object once it has been created like this: from guizero import App app = App(title=\"My app\", height=300, width=200) app.title = \"A different title\" app.display() This will display the app with the updated title:","title":"Examples"},{"location":"blocking/","text":"Loops and sleeping You may be used to writing programs which contain loops or make use of the sleep() command, but find when you try to use these with guizero they cause your GUI to freeze. This is because guizero (in common with almost all GUIs) operates an event driven model of programming which may be different to the one you are familiar with. Your first guizero program might look a bit like this: from guizero import App app = App(\"Hello world\") app.display() The line of code app.display() doesn't just display the app - it enters an infinite event loop which is watching and waiting for events to happen on the GUI. Events include things like the user clicking on a button, moving a slider, typing in a text box etc. No code written after this line will ever execute because the event loop is infinite. Example Suppose you want a counter on your GUI to start counting up by 1 every second. You might be tempted to write a program like this: from guizero import App, Text from time import sleep app = App(\"Hello world\") text = Text(app, text=\"1\") while True: text.value = int(text.value) + 1 sleep(1) app.display() If you run this program, you'll see that this does not have the desired effect - your program crashes! This is because you have blocked the updating of your GUI in two ways: The sleep() command - whilst your program is sleeping, the GUI will not update and you will not be able to click on anything. The while loop - once you enter this loop, your GUI will never update ever again and will probably crash. Solution This behaviour is not a bug within guizero or tkinter. You must write GUI based programs in a different way to the one you may be used to. If you want to repeatedly perform an action you would do it like this: Write a function which performs the desired action (in this example counter() ) Set a callback to that function. You can either schedule the same callback to occur repeatedly after a given number of milliseconds (in this example 1000 ), or you can schedule it only once. from guizero import App, Text # Action you would like to perform def counter(): text.value = int(text.value) + 1 app = App(\"Hello world\") text = Text(app, text=\"1\") text.repeat(1000, counter) # Schedule call to counter() every 1000ms app.display()","title":"Loops and sleeping"},{"location":"blocking/#loops-and-sleeping","text":"You may be used to writing programs which contain loops or make use of the sleep() command, but find when you try to use these with guizero they cause your GUI to freeze. This is because guizero (in common with almost all GUIs) operates an event driven model of programming which may be different to the one you are familiar with. Your first guizero program might look a bit like this: from guizero import App app = App(\"Hello world\") app.display() The line of code app.display() doesn't just display the app - it enters an infinite event loop which is watching and waiting for events to happen on the GUI. Events include things like the user clicking on a button, moving a slider, typing in a text box etc. No code written after this line will ever execute because the event loop is infinite.","title":"Loops and sleeping"},{"location":"blocking/#example","text":"Suppose you want a counter on your GUI to start counting up by 1 every second. You might be tempted to write a program like this: from guizero import App, Text from time import sleep app = App(\"Hello world\") text = Text(app, text=\"1\") while True: text.value = int(text.value) + 1 sleep(1) app.display() If you run this program, you'll see that this does not have the desired effect - your program crashes! This is because you have blocked the updating of your GUI in two ways: The sleep() command - whilst your program is sleeping, the GUI will not update and you will not be able to click on anything. The while loop - once you enter this loop, your GUI will never update ever again and will probably crash.","title":"Example"},{"location":"blocking/#solution","text":"This behaviour is not a bug within guizero or tkinter. You must write GUI based programs in a different way to the one you may be used to. If you want to repeatedly perform an action you would do it like this: Write a function which performs the desired action (in this example counter() ) Set a callback to that function. You can either schedule the same callback to occur repeatedly after a given number of milliseconds (in this example 1000 ), or you can schedule it only once. from guizero import App, Text # Action you would like to perform def counter(): text.value = int(text.value) + 1 app = App(\"Hello world\") text = Text(app, text=\"1\") text.repeat(1000, counter) # Schedule call to counter() every 1000ms app.display()","title":"Solution"},{"location":"book/","text":"Book Create Graphical User Interfaces with Python The authors of guizero have written a book containing ten fun guizero projects. The book starts from a very basic GUI and shows you how to create gradually more complex GUI programs including a painting program and a stop-motion animation creator. You can buy the book in print or download it as a free PDF .","title":"Book"},{"location":"book/#book","text":"","title":"Book"},{"location":"book/#create-graphical-user-interfaces-with-python","text":"The authors of guizero have written a book containing ten fun guizero projects. The book starts from a very basic GUI and shows you how to create gradually more complex GUI programs including a painting program and a stop-motion animation creator. You can buy the book in print or download it as a free PDF .","title":"Create Graphical User Interfaces with Python"},{"location":"box/","text":"Box (Contains a tkinter.Frame object) __init__( self, master, layout=\"auto\", grid=None, align=None, visible=True, enabled=None, width=None, height=None, border=None) What is it? The Box object is an invisible container which can contain other widgets. It is the only object other than App and Window which can act as the master for other objects and can have its own layout manager. You can use the Box object to group other objects within your GUI. How do I make one? Create a Box object like this: from guizero import App, Box app = App() box = Box(app) app.display() Starting parameters When you create a Box object you must specify a master, and you can specify any of the optional parameters. Specify parameters in the brackets like this: box = Box(app, layout=\"grid\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. layout string \"auto\" - Whether widgets inside this box pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" border int None No Sets the border thickness. 0 or False is no border. True or value > 1 sets a border. Methods You can call the following methods on a Box object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the box so that they cannot be interacted with destroy() - - Destroys the widget enable() - - Enables all the widgets in the box focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget set_border(thickness, color) thickness (int), color ( color ) - Sets the border thickness and color. Setting thickness to 0 will result in no border. show() - - Displays the widget if it was previously hidden Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container border int The border thickness, setting to 0 or False (the default) there is no border. bg color The background colour of the widget children list(widgets) A list of widgets in this container enabled boolean True if the box is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid font string The font that widgets should use height size Set the height of the widget in pixels or to \"fill\" layout string The layout being used by the Box ( \"auto\" ) or ( \"grid\" ) master App The App object to which this box belongs text_size int The size of the text widgets should use text_color color The colour of the text widgets should use visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" Examples Putting widgets in a Box A Box object is invisible, but it can contain other widgets. In this example, there are two Text objects. One has box as its master, the other has app as its master. from guizero import App, Box, Text app = App(title=\"My app\", height=300, width=400) box = Box(app) text1 = Text(box, text=\"Hello from the box\", size=14, text_color=\"red\", font=\"Arial\") text2 = Text(app, text=\"Hello from the app\", size=14, text_color=\"blue\", font=\"Courier New\") app.display() Grouping objects within a Box It is useful to put objects in a box to group them together. For example here we have given the app a grid layout, then placed some text at [0,0] and the Box object at [1,0]. This means that the text will appear on the left, and the contents of the Box will appear on the right. The Box object itself has a grid layout and contains six buttons which are positioned on a separate grid layout belonging to the box. from guizero import App, Text, Box, PushButton def do_nothing(): return 0 app = App(title=\"My app\", height=300, width=300, layout=\"grid\") text = Text(app, text=\"Some text here\", grid=[0,0]) box = Box(app, layout=\"grid\", grid=[1,0]) button1 = PushButton(box, command=do_nothing, text=\"1\", grid=[0,0]) button2 = PushButton(box, command=do_nothing, text=\"2\", grid=[1,0]) button3 = PushButton(box, command=do_nothing, text=\"3\", grid=[2,0]) button4 = PushButton(box, command=do_nothing, text=\"4\", grid=[0,1]) button5 = PushButton(box, command=do_nothing, text=\"5\", grid=[1,1]) button6 = PushButton(box, command=do_nothing, text=\"6\", grid=[2,1]) app.display()","title":"Box"},{"location":"box/#box","text":"(Contains a tkinter.Frame object) __init__( self, master, layout=\"auto\", grid=None, align=None, visible=True, enabled=None, width=None, height=None, border=None)","title":"Box"},{"location":"box/#what-is-it","text":"The Box object is an invisible container which can contain other widgets. It is the only object other than App and Window which can act as the master for other objects and can have its own layout manager. You can use the Box object to group other objects within your GUI.","title":"What is it?"},{"location":"box/#how-do-i-make-one","text":"Create a Box object like this: from guizero import App, Box app = App() box = Box(app) app.display()","title":"How do I make one?"},{"location":"box/#starting-parameters","text":"When you create a Box object you must specify a master, and you can specify any of the optional parameters. Specify parameters in the brackets like this: box = Box(app, layout=\"grid\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. layout string \"auto\" - Whether widgets inside this box pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" border int None No Sets the border thickness. 0 or False is no border. True or value > 1 sets a border.","title":"Starting parameters"},{"location":"box/#methods","text":"You can call the following methods on a Box object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the box so that they cannot be interacted with destroy() - - Destroys the widget enable() - - Enables all the widgets in the box focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget set_border(thickness, color) thickness (int), color ( color ) - Sets the border thickness and color. Setting thickness to 0 will result in no border. show() - - Displays the widget if it was previously hidden","title":"Methods"},{"location":"box/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container border int The border thickness, setting to 0 or False (the default) there is no border. bg color The background colour of the widget children list(widgets) A list of widgets in this container enabled boolean True if the box is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid font string The font that widgets should use height size Set the height of the widget in pixels or to \"fill\" layout string The layout being used by the Box ( \"auto\" ) or ( \"grid\" ) master App The App object to which this box belongs text_size int The size of the text widgets should use text_color color The colour of the text widgets should use visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\"","title":"Properties"},{"location":"box/#examples","text":"Putting widgets in a Box A Box object is invisible, but it can contain other widgets. In this example, there are two Text objects. One has box as its master, the other has app as its master. from guizero import App, Box, Text app = App(title=\"My app\", height=300, width=400) box = Box(app) text1 = Text(box, text=\"Hello from the box\", size=14, text_color=\"red\", font=\"Arial\") text2 = Text(app, text=\"Hello from the app\", size=14, text_color=\"blue\", font=\"Courier New\") app.display() Grouping objects within a Box It is useful to put objects in a box to group them together. For example here we have given the app a grid layout, then placed some text at [0,0] and the Box object at [1,0]. This means that the text will appear on the left, and the contents of the Box will appear on the right. The Box object itself has a grid layout and contains six buttons which are positioned on a separate grid layout belonging to the box. from guizero import App, Text, Box, PushButton def do_nothing(): return 0 app = App(title=\"My app\", height=300, width=300, layout=\"grid\") text = Text(app, text=\"Some text here\", grid=[0,0]) box = Box(app, layout=\"grid\", grid=[1,0]) button1 = PushButton(box, command=do_nothing, text=\"1\", grid=[0,0]) button2 = PushButton(box, command=do_nothing, text=\"2\", grid=[1,0]) button3 = PushButton(box, command=do_nothing, text=\"3\", grid=[2,0]) button4 = PushButton(box, command=do_nothing, text=\"4\", grid=[0,1]) button5 = PushButton(box, command=do_nothing, text=\"5\", grid=[1,1]) button6 = PushButton(box, command=do_nothing, text=\"6\", grid=[2,1]) app.display()","title":"Examples"},{"location":"buttongroup/","text":"ButtonGroup (Contains a tkinter.Frame object) __init__( self, master, options=[], selected=None, horizontal=False, command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None) What is it? The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option. How do I make one? Create a ButtonGroup object like this: from guizero import App, ButtonGroup app = App() choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=\"cheese\") app.display() Starting parameters When you create a ButtonGroup object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets like this: choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=1) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options list or 2D List - No Either a list or a 2D list of [text, value] pairs. If a 2D list is specified, the first item in the pair will be displayed on the interface, and the second item will be a hidden value associated with this option. selected string - - The option that should be selected, if a value isn't provided the first option will be selected. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the selected option changes. args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid list [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal boolean False - Whether the buttons stack vertically or horizontally. (Defaults to vertical) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on an ButtonGroup object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the ButtonGroup. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget get_group_as_list() - list Returns a list containing all of the text/hidden value pairs from the ButtonGroup (useful for debugging) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), option (string) - Insert a new option in the ButtonGroup at index remove(option) item (string) Boolean Removes the first option from the ButtonGroup. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the selected option changes Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The hidden value associated with the currently selected option value_text string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your ButtonGroup object is called choice you would write choice.value . You can set the property (for example choice.value = \"2\" ) or get the value of the property to use (for example print(choice.value) ). Examples Creating a ButtonGroup with a 2D list If you want to create a ButtonGroup object with your own hidden values you can specify a 2D list of options: from guizero import App, ButtonGroup, Text def update_text(): what_is_selected.value = activities.value app = App() activities = ButtonGroup(app, options=[ [\"Roller Skating\", \"skate\"], [\"White water rafting\", \"WWR\"], [\"Mountain climbing\", \"climb\"] ], selected=\"skate\", command=update_text) what_is_selected = Text(app, text=\"skate\") app.display()","title":"ButtonGroup"},{"location":"buttongroup/#buttongroup","text":"(Contains a tkinter.Frame object) __init__( self, master, options=[], selected=None, horizontal=False, command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None)","title":"ButtonGroup"},{"location":"buttongroup/#what-is-it","text":"The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option.","title":"What is it?"},{"location":"buttongroup/#how-do-i-make-one","text":"Create a ButtonGroup object like this: from guizero import App, ButtonGroup app = App() choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=\"cheese\") app.display()","title":"How do I make one?"},{"location":"buttongroup/#starting-parameters","text":"When you create a ButtonGroup object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets like this: choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=1) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options list or 2D List - No Either a list or a 2D list of [text, value] pairs. If a 2D list is specified, the first item in the pair will be displayed on the interface, and the second item will be a hidden value associated with this option. selected string - - The option that should be selected, if a value isn't provided the first option will be selected. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the selected option changes. args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid list [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal boolean False - Whether the buttons stack vertically or horizontally. (Defaults to vertical) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"buttongroup/#methods","text":"You can call the following methods on an ButtonGroup object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the ButtonGroup. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget get_group_as_list() - list Returns a list containing all of the text/hidden value pairs from the ButtonGroup (useful for debugging) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), option (string) - Insert a new option in the ButtonGroup at index remove(option) item (string) Boolean Removes the first option from the ButtonGroup. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the selected option changes","title":"Methods"},{"location":"buttongroup/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The hidden value associated with the currently selected option value_text string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your ButtonGroup object is called choice you would write choice.value . You can set the property (for example choice.value = \"2\" ) or get the value of the property to use (for example print(choice.value) ).","title":"Properties"},{"location":"buttongroup/#examples","text":"Creating a ButtonGroup with a 2D list If you want to create a ButtonGroup object with your own hidden values you can specify a 2D list of options: from guizero import App, ButtonGroup, Text def update_text(): what_is_selected.value = activities.value app = App() activities = ButtonGroup(app, options=[ [\"Roller Skating\", \"skate\"], [\"White water rafting\", \"WWR\"], [\"Mountain climbing\", \"climb\"] ], selected=\"skate\", command=update_text) what_is_selected = Text(app, text=\"skate\") app.display()","title":"Examples"},{"location":"changelog/","text":"guizero 1.1.0 - 2019-10-25 Added ability to be able to change the grid of a widget at room time Added hide_text to TextBox for use with passwords Added open file and folder popups select_file and select_folder Changes to Text to better support cascading of text color, font and size Various documentation updates contributors martinohanlon , lawsie 1.0.0 - 2019-07-11 Previously deprecated methods have now been removed Resolved race condition in the repeat , cancel methods Refactored alerts (renamed pop-ups), they can now also be called from App & Window objects Added question pop-up Created windows MSI installer for guizero Deprecated App.on_closed method and replaced with App.when_closed property contributors martinohanlon , lawsie , MrYsLab , scotty3785 0.6.4 - 2019-05-08) Fixed TextBox command to be on key release Fix Text not inheriting properties Added add_tk_warning when inserting a tk widget into the wrong container Update docs contributors martinohanlon , hyle01 0.6.3 - 2019-04-18 ListBox scrollbar bug fix (again) Removed pillow requires dependency Added pillow as an extra dependency pip3 install guizero[images] Installation instructions update contributors martinohanlon , lawsie 0.6.2 - 2019-04-05 Ability to add tk widgets into a guizero app with .add_tk_widget() ListBox scrollbar bug fix MenuBar background colour bug fix setup.py changes to allow dunders to be accessed from guizero module contributors martinohanlon , lawsie 0.6.1 - 2019-03-08 New Drawing widget for creating \"drawings\" Added full screen support for App and Window Doc updates Minor bug fixes contributors martinohanlon , lawsie 0.6.0 - 2019-02-08 Refactoring of layout functions Enabled align for the auto layout width and height can now be set to \"fill\" Modified setup.py to restrict install to Python 3 only Minor bug fixes contributors martinohanlon , bennuttal , yeyeto2788 , knowledgejunkie , lawsie 0.5.4 - 2018-10-16 Fixed Box to size properly Added border to Box Added width and height to widget constructor Added resize method to all widgets Minor bug fixes contributors martinohanlon 0.5.3 - 2018-07-18 Various bug fixes wrapping multiline TextBox data ButtonGroup , ComboBox now allow 0 options at init Minimum pillow version is now 4.3.0 update method added to Add and Window contributors martinohanlon , scotty3785 , MrYsLab , bsimmo 0.5.2 - 2018-06-01 Refactoring of ButtonGroup , including API breaking change - if no hidden values are specified, ButtonGroup.value now returns the text value not a generate string number #178 A widgets properties bg , text_color , text_size , font , width , height can be restored by to their default by setting them to None #181 Slider is now sized properly when orientated vertically #186 Combo and ButtonGroup now support append , insert , remove , clear and depreciated add_option #180 Refactoring of class hierarchy Various bug fixes contributors martinohanlon 0.5.1 - 2018-05-14 App , Window , Box now support the following properties and will cascade them to widgets within them: bg text_color text_size font enabled Introduced ListBox Bug fixes relating to bg and text_color causing widgets to change colour when selected Minor bug fixes with CheckBox , Waffle and Combo Documentation fixes and updates contributors to this release martinohanlon , lawsie , Harlekuin 0.5.0 - 2018-04-10 v0.5.0 includes significant refactoring of the guizero code base and introduces many new features New image functionality introduced when PIL is installed: images can be passed as Tk.PhotoImage or PIL.Image objects as well as file paths more images types are supported animated images (gifs) are supported images are scaled when the size is changed ButtonGroup - selected is now optional, enabled properties now supported, value_text fixed Fixed multiple App bug Created Window class to support multi-window applications Added multiline and scrollbar functionality to TextBox Refactored guizero to introduce a class hierarchy making guizero wide code changes easier to implement Added the following events to all widgets, this should be considered experimental in this release: when_clicked when_left_button_pressed when_left_button_released when_right_button_pressed when_right_button_released when_key_pressed when_key_released when_mouse_enters when_mouse_leaves when_mouse_dragged Various minor bug fixes Automated tests have been introduced contributors to this release martinohanlon , scotty3785 , IDF31 , drussell1974 - ta very much :) 0.4.5 - 2018-03-04 colors can now be specified as either \"red\" , \"#ffffff\" , or (red, green, blue) change Picture image startup parameter to be optional updated Picture and PushButton errors and docs to show that PNG and GIF images can be used in Windows & Linux refactored Waffle resolving bugs that setting properties didnt change its appearance changed waffle so you can reference a pixel using waffle[x,y] added text_color , text_size and font properties to Slider added width and height properties to: Box ButtonGroup CheckBox Combo Picture Slider Text added width property to: TextBox contributors to this release Coal0 , martinohanlon , scotty3785 - :) 0.4.4 - 2018-02-12 made PushButton command optional Combo command functions can now have 0 arguments Waffle command functions can now have 0 arguments refactored command functions and added update_command to: ButtonGroup CheckBox Combo PushButton Slider Waffle refactored text_color , text_size and font properties and added them to: ButtonGroup Combo CheckBox PushButton Text TextBox refactored bg (background) and added to: Box ButtonGroup CheckBox Combo Picture PushButton Slider Text TextBox contributors to this release m4ddav3 , Coal0 , lawsie , martinohanlon - :) 0.4.3 - 2018-01-10 Minor features, bug fixes and internal refactoring added xspan , yspan to grid layout (Credit: penguintutor ) fixed show() for widgets in a grid layout added master , grid , align and visible properties to widgets added layout property to containers fixed Waffle height (Credit: scotty3785 ) minor doc updates 0.4.2 was never released due to some pypi / wheel problems 0.4.1 - 2017-12-28 Bug fixes and deployment test PushButton bug fixes added enabled property to widgets which support Enable / Disable documentation tidy up added build notes to documentation 0.4 - 2017-12-19 Thank you to everyone who has taken time to contribute code, suggest helpful improvements and report their use of the library. I am extremely grateful to the following people who have contributed pull requests since the last version: bcroston , bennuttall , Coal0 , martinohanlon and scotty3785 I am also very pleased to announce that martinohanlon has very kindly agreed to maintain guizero whilst I am on maternity leave, beginning December 2017. General changes: All classes rewritten with internal Tk objects rather than extending the Tk object, meaning you can access all Tk functionality as Object.tk.tkmethod() (Credit for idea: bennuttall ) Improved use of library with tab complete editors (e.g. ipython) \u2013 only the guizero properties and methods are listed so the list is shorter and more friendly. (Credit for idea: bennuttall ) [Bug fix] Grid layout now lays items out properly. Previously the x and y axes were flipped. (Whoops!) This fix will cause apps with a grid layout to look different, but now behave correctly. You may need to update old code as a result of this change. All classes now inherit from mixins, adding 9 new common methods usable on most widgets - after() , cancel() , destroy() , disable() , enable() , focus() , hide() , show() , repeat() , (Credit: Coal0 and martinohanlon ) The new repeat() method allows you to easily specify a repeated callback to a function, making it extremely easy to perform repetitive actions such as updating the GUI based on readings from a sensor. Documentation and examples have been improved and updated App: New constructor argument bg replaces deprecated bgcolor argument. If both are specified, bg overrides bgcolor . set_title() and bgcolor() methods are now deprecated and have been replaced by title and bg properties New additional properties width and height ButtonGroup: get() and set() methods are now deprecated and have been replaced by the value property New value_text property to get the text associated with the selected option CheckBox: get_text() , get_value() and change_text() methods are now deprecated and have been replaced by the value and text properties New toggle() method added Combo: get() and set() methods are now deprecated and have been replaced by the value property [Bug fix] set_default() now correctly resets the combo back to its originally specified value, whether this was the first option or a specified option Picture: set() method is now deprecated and has been replaced by the value property PushButton: set_text() method is now deprecated and has been replaced by the text property New properties for text_color , bg , font , text_size , height and width \u2013 make your buttons look pretty! Find out whether a button is pressed (1) or released (0) with the new value property New icon() method to set the icon of a button after it is created toggle_state() method deprecated and renamed to toggle() for consistency Slider: New value property for getting and setting the value of the slider Text: New constructor arguments text_color and bg color constructor argument now deprecated and replaced by text_color . If both are specified, text_color overrides color . get() , set() , color() , font_face() and font_size() methods are now deprecated, replaced by properties value , text_color , bg , font and size TextBox: get() and set() methods now deprecated and replaced by value property Waffle: All waffles will now have a memory. The remember constructor argument remains for backwards compatibility only and will be removed in a future release . You can now click on a Waffle, and specify a command to run when the Waffle is clicked on. The function given as the command should take two arguments as it will be passed the x, y coordinates of the pixel that was clicked. (Credit: scotty3785 ) Changed internal implementation of the Waffle so it should now be able to redraw more efficiently. (Credit: scotty3785 )","title":"Change log"},{"location":"changelog/#guizero","text":"","title":"guizero"},{"location":"changelog/#110-2019-10-25","text":"Added ability to be able to change the grid of a widget at room time Added hide_text to TextBox for use with passwords Added open file and folder popups select_file and select_folder Changes to Text to better support cascading of text color, font and size Various documentation updates contributors martinohanlon , lawsie","title":"1.1.0 - 2019-10-25"},{"location":"changelog/#100-2019-07-11","text":"Previously deprecated methods have now been removed Resolved race condition in the repeat , cancel methods Refactored alerts (renamed pop-ups), they can now also be called from App & Window objects Added question pop-up Created windows MSI installer for guizero Deprecated App.on_closed method and replaced with App.when_closed property contributors martinohanlon , lawsie , MrYsLab , scotty3785","title":"1.0.0 - 2019-07-11"},{"location":"changelog/#064-2019-05-08","text":"Fixed TextBox command to be on key release Fix Text not inheriting properties Added add_tk_warning when inserting a tk widget into the wrong container Update docs contributors martinohanlon , hyle01","title":"0.6.4 - 2019-05-08)"},{"location":"changelog/#063-2019-04-18","text":"ListBox scrollbar bug fix (again) Removed pillow requires dependency Added pillow as an extra dependency pip3 install guizero[images] Installation instructions update contributors martinohanlon , lawsie","title":"0.6.3 - 2019-04-18"},{"location":"changelog/#062-2019-04-05","text":"Ability to add tk widgets into a guizero app with .add_tk_widget() ListBox scrollbar bug fix MenuBar background colour bug fix setup.py changes to allow dunders to be accessed from guizero module contributors martinohanlon , lawsie","title":"0.6.2 - 2019-04-05"},{"location":"changelog/#061-2019-03-08","text":"New Drawing widget for creating \"drawings\" Added full screen support for App and Window Doc updates Minor bug fixes contributors martinohanlon , lawsie","title":"0.6.1 - 2019-03-08"},{"location":"changelog/#060-2019-02-08","text":"Refactoring of layout functions Enabled align for the auto layout width and height can now be set to \"fill\" Modified setup.py to restrict install to Python 3 only Minor bug fixes contributors martinohanlon , bennuttal , yeyeto2788 , knowledgejunkie , lawsie","title":"0.6.0 - 2019-02-08"},{"location":"changelog/#054-2018-10-16","text":"Fixed Box to size properly Added border to Box Added width and height to widget constructor Added resize method to all widgets Minor bug fixes contributors martinohanlon","title":"0.5.4 - 2018-10-16"},{"location":"changelog/#053-2018-07-18","text":"Various bug fixes wrapping multiline TextBox data ButtonGroup , ComboBox now allow 0 options at init Minimum pillow version is now 4.3.0 update method added to Add and Window contributors martinohanlon , scotty3785 , MrYsLab , bsimmo","title":"0.5.3 - 2018-07-18"},{"location":"changelog/#052-2018-06-01","text":"Refactoring of ButtonGroup , including API breaking change - if no hidden values are specified, ButtonGroup.value now returns the text value not a generate string number #178 A widgets properties bg , text_color , text_size , font , width , height can be restored by to their default by setting them to None #181 Slider is now sized properly when orientated vertically #186 Combo and ButtonGroup now support append , insert , remove , clear and depreciated add_option #180 Refactoring of class hierarchy Various bug fixes contributors martinohanlon","title":"0.5.2 - 2018-06-01"},{"location":"changelog/#051-2018-05-14","text":"App , Window , Box now support the following properties and will cascade them to widgets within them: bg text_color text_size font enabled Introduced ListBox Bug fixes relating to bg and text_color causing widgets to change colour when selected Minor bug fixes with CheckBox , Waffle and Combo Documentation fixes and updates contributors to this release martinohanlon , lawsie , Harlekuin","title":"0.5.1 - 2018-05-14"},{"location":"changelog/#050-2018-04-10","text":"v0.5.0 includes significant refactoring of the guizero code base and introduces many new features New image functionality introduced when PIL is installed: images can be passed as Tk.PhotoImage or PIL.Image objects as well as file paths more images types are supported animated images (gifs) are supported images are scaled when the size is changed ButtonGroup - selected is now optional, enabled properties now supported, value_text fixed Fixed multiple App bug Created Window class to support multi-window applications Added multiline and scrollbar functionality to TextBox Refactored guizero to introduce a class hierarchy making guizero wide code changes easier to implement Added the following events to all widgets, this should be considered experimental in this release: when_clicked when_left_button_pressed when_left_button_released when_right_button_pressed when_right_button_released when_key_pressed when_key_released when_mouse_enters when_mouse_leaves when_mouse_dragged Various minor bug fixes Automated tests have been introduced contributors to this release martinohanlon , scotty3785 , IDF31 , drussell1974 - ta very much :)","title":"0.5.0 - 2018-04-10"},{"location":"changelog/#045-2018-03-04","text":"colors can now be specified as either \"red\" , \"#ffffff\" , or (red, green, blue) change Picture image startup parameter to be optional updated Picture and PushButton errors and docs to show that PNG and GIF images can be used in Windows & Linux refactored Waffle resolving bugs that setting properties didnt change its appearance changed waffle so you can reference a pixel using waffle[x,y] added text_color , text_size and font properties to Slider added width and height properties to: Box ButtonGroup CheckBox Combo Picture Slider Text added width property to: TextBox contributors to this release Coal0 , martinohanlon , scotty3785 - :)","title":"0.4.5 - 2018-03-04"},{"location":"changelog/#044-2018-02-12","text":"made PushButton command optional Combo command functions can now have 0 arguments Waffle command functions can now have 0 arguments refactored command functions and added update_command to: ButtonGroup CheckBox Combo PushButton Slider Waffle refactored text_color , text_size and font properties and added them to: ButtonGroup Combo CheckBox PushButton Text TextBox refactored bg (background) and added to: Box ButtonGroup CheckBox Combo Picture PushButton Slider Text TextBox contributors to this release m4ddav3 , Coal0 , lawsie , martinohanlon - :)","title":"0.4.4 - 2018-02-12"},{"location":"changelog/#043-2018-01-10","text":"Minor features, bug fixes and internal refactoring added xspan , yspan to grid layout (Credit: penguintutor ) fixed show() for widgets in a grid layout added master , grid , align and visible properties to widgets added layout property to containers fixed Waffle height (Credit: scotty3785 ) minor doc updates 0.4.2 was never released due to some pypi / wheel problems","title":"0.4.3 - 2018-01-10"},{"location":"changelog/#041-2017-12-28","text":"Bug fixes and deployment test PushButton bug fixes added enabled property to widgets which support Enable / Disable documentation tidy up added build notes to documentation","title":"0.4.1 - 2017-12-28"},{"location":"changelog/#04-2017-12-19","text":"Thank you to everyone who has taken time to contribute code, suggest helpful improvements and report their use of the library. I am extremely grateful to the following people who have contributed pull requests since the last version: bcroston , bennuttall , Coal0 , martinohanlon and scotty3785 I am also very pleased to announce that martinohanlon has very kindly agreed to maintain guizero whilst I am on maternity leave, beginning December 2017. General changes: All classes rewritten with internal Tk objects rather than extending the Tk object, meaning you can access all Tk functionality as Object.tk.tkmethod() (Credit for idea: bennuttall ) Improved use of library with tab complete editors (e.g. ipython) \u2013 only the guizero properties and methods are listed so the list is shorter and more friendly. (Credit for idea: bennuttall ) [Bug fix] Grid layout now lays items out properly. Previously the x and y axes were flipped. (Whoops!) This fix will cause apps with a grid layout to look different, but now behave correctly. You may need to update old code as a result of this change. All classes now inherit from mixins, adding 9 new common methods usable on most widgets - after() , cancel() , destroy() , disable() , enable() , focus() , hide() , show() , repeat() , (Credit: Coal0 and martinohanlon ) The new repeat() method allows you to easily specify a repeated callback to a function, making it extremely easy to perform repetitive actions such as updating the GUI based on readings from a sensor. Documentation and examples have been improved and updated App: New constructor argument bg replaces deprecated bgcolor argument. If both are specified, bg overrides bgcolor . set_title() and bgcolor() methods are now deprecated and have been replaced by title and bg properties New additional properties width and height ButtonGroup: get() and set() methods are now deprecated and have been replaced by the value property New value_text property to get the text associated with the selected option CheckBox: get_text() , get_value() and change_text() methods are now deprecated and have been replaced by the value and text properties New toggle() method added Combo: get() and set() methods are now deprecated and have been replaced by the value property [Bug fix] set_default() now correctly resets the combo back to its originally specified value, whether this was the first option or a specified option Picture: set() method is now deprecated and has been replaced by the value property PushButton: set_text() method is now deprecated and has been replaced by the text property New properties for text_color , bg , font , text_size , height and width \u2013 make your buttons look pretty! Find out whether a button is pressed (1) or released (0) with the new value property New icon() method to set the icon of a button after it is created toggle_state() method deprecated and renamed to toggle() for consistency Slider: New value property for getting and setting the value of the slider Text: New constructor arguments text_color and bg color constructor argument now deprecated and replaced by text_color . If both are specified, text_color overrides color . get() , set() , color() , font_face() and font_size() methods are now deprecated, replaced by properties value , text_color , bg , font and size TextBox: get() and set() methods now deprecated and replaced by value property Waffle: All waffles will now have a memory. The remember constructor argument remains for backwards compatibility only and will be removed in a future release . You can now click on a Waffle, and specify a command to run when the Waffle is clicked on. The function given as the command should take two arguments as it will be passed the x, y coordinates of the pixel that was clicked. (Credit: scotty3785 ) Changed internal implementation of the Waffle so it should now be able to redraw more efficiently. (Credit: scotty3785 )","title":"0.4 - 2017-12-19"},{"location":"checkbox/","text":"CheckBox (Contains a tkinter.Checkbutton object) __init__( self, master, text=\"\", command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None) What is it? The CheckBox object displays a check box to allow an option to be ticked or un-ticked. How do I make one? Create a CheckBox object like this: from guizero import App, CheckBox app = App() checkbox = CheckBox(app, text=\"Add extra glitter\") app.display() Starting parameters When you create a CheckBox object you must specify master and text and you can specify any of the optional parameters. Specify parameters in the brackets, like this: checkbox = CheckBox(app, text=\"Add extra glitter\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs text string \"\" No The text to display next to the check box align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when this checkbox is ticked/unticked args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on a CheckBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Switches the CheckBox to the opposite of its current value. i.e. if it is ticked, untick it and vice versa update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the checkbox is ticked/unticked Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text string The text associated with the checkbox value int 1 if the CheckBox is ticked or 0 if it is not ticked visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your CheckBox object is called checkbox you would write checkbox.value . You can set the property (for example checkbox.value = 1 ) or get the value of the property to use (for example print(checkbox.value) ). Examples Creating multiple CheckBoxes Create multiple CheckBoxes like this. from guizero import App, CheckBox app = App() glitter = CheckBox(app, text=\"Add glitter\") sparkles = CheckBox(app, text=\"Add sparkles\") app.display() Calling a function when a CheckBox value changes You can call a function when the value of a CheckBox changes (becomes checked or unchecked). In this particular example all three CheckBoxes call the same function, but it is possible for each CheckBox object to call a different function. from guizero import App, Text, CheckBox, TextBox def calculate_extras(): total = 0 if syrup.value == 1: total += 20 if sprinkles.value == 1: total += 10 if cream.value == 1: total += 50 cost.value = total app = App() questions = Text(app, text=\"What would you like with your coffee?\") syrup = CheckBox(app, text=\"Caramel syrup (20p)\", command=calculate_extras) sprinkles = CheckBox(app, text=\"Chocolate sprinkles (10p)\", command=calculate_extras) cream = CheckBox(app, text=\"Whipped cream (50p)\", command=calculate_extras) cost_of_extras = Text(app, text=\"Cost of extras:\") cost = TextBox(app, text=\"0\") app.display()","title":"CheckBox"},{"location":"checkbox/#checkbox","text":"(Contains a tkinter.Checkbutton object) __init__( self, master, text=\"\", command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None)","title":"CheckBox"},{"location":"checkbox/#what-is-it","text":"The CheckBox object displays a check box to allow an option to be ticked or un-ticked.","title":"What is it?"},{"location":"checkbox/#how-do-i-make-one","text":"Create a CheckBox object like this: from guizero import App, CheckBox app = App() checkbox = CheckBox(app, text=\"Add extra glitter\") app.display()","title":"How do I make one?"},{"location":"checkbox/#starting-parameters","text":"When you create a CheckBox object you must specify master and text and you can specify any of the optional parameters. Specify parameters in the brackets, like this: checkbox = CheckBox(app, text=\"Add extra glitter\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs text string \"\" No The text to display next to the check box align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when this checkbox is ticked/unticked args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"checkbox/#methods","text":"You can call the following methods on a CheckBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Switches the CheckBox to the opposite of its current value. i.e. if it is ticked, untick it and vice versa update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the checkbox is ticked/unticked","title":"Methods"},{"location":"checkbox/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text string The text associated with the checkbox value int 1 if the CheckBox is ticked or 0 if it is not ticked visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your CheckBox object is called checkbox you would write checkbox.value . You can set the property (for example checkbox.value = 1 ) or get the value of the property to use (for example print(checkbox.value) ).","title":"Properties"},{"location":"checkbox/#examples","text":"Creating multiple CheckBoxes Create multiple CheckBoxes like this. from guizero import App, CheckBox app = App() glitter = CheckBox(app, text=\"Add glitter\") sparkles = CheckBox(app, text=\"Add sparkles\") app.display() Calling a function when a CheckBox value changes You can call a function when the value of a CheckBox changes (becomes checked or unchecked). In this particular example all three CheckBoxes call the same function, but it is possible for each CheckBox object to call a different function. from guizero import App, Text, CheckBox, TextBox def calculate_extras(): total = 0 if syrup.value == 1: total += 20 if sprinkles.value == 1: total += 10 if cream.value == 1: total += 50 cost.value = total app = App() questions = Text(app, text=\"What would you like with your coffee?\") syrup = CheckBox(app, text=\"Caramel syrup (20p)\", command=calculate_extras) sprinkles = CheckBox(app, text=\"Chocolate sprinkles (10p)\", command=calculate_extras) cream = CheckBox(app, text=\"Whipped cream (50p)\", command=calculate_extras) cost_of_extras = Text(app, text=\"Cost of extras:\") cost = TextBox(app, text=\"0\") app.display()","title":"Examples"},{"location":"colors/","text":"Colors (or Colo u rs) You can set colors in guizero using: the name of the color - white a #rgb hex value - #ffffff a list of rgb values - (255,255,255) Colors can be used as either starting parameters, for example: app = App(bg = \"red\") app = App(bg = \"#ff0000\") app = App(bg = (255, 0, 0)) or as properties, for example: text = Text(app, text = \"hi\") text.text_color = \"green\" text.text_color = \"#00ff00\" text.text_color = (0, 255, 0) If a color is set using a list of rgb values ( (255,255,255) ) it will be returned as an #rgb hex value ( #ffffff ) Color names Some color names can be given as strings, for example white black red green blue yellow A complete list of color names is available at wiki.tcl.tk/37701 rgb hex value A rgb color value must start with a # and 6 characters following, 2 each for the red, green and blue value in hex. Each value must be 00 - ff . Here are some examples: white = #ffffff black = #000000 red = #ff0000 green = #00ff00 blue = #0000ff yellow = #ffff00 You can mix your own color by changing the red, green and blue values. There is a RGB calculator application at https://www.w3schools.com/colors/colors_rgb.asp where you can create your own color and get the #rrggbb value. rgb list The (red, green, blue) list color must contain three elements in the order red, green, blue. Each value must be between 0 - 255. Here are some examples: white = (255, 255, 255) black = (0, 0, 0) red = (255, 0, 0) green = (0, 255, 0) blue = (0, 0, 255) yellow = (255, 255, 0)","title":"Colors"},{"location":"colors/#colors-or-colours","text":"You can set colors in guizero using: the name of the color - white a #rgb hex value - #ffffff a list of rgb values - (255,255,255) Colors can be used as either starting parameters, for example: app = App(bg = \"red\") app = App(bg = \"#ff0000\") app = App(bg = (255, 0, 0)) or as properties, for example: text = Text(app, text = \"hi\") text.text_color = \"green\" text.text_color = \"#00ff00\" text.text_color = (0, 255, 0) If a color is set using a list of rgb values ( (255,255,255) ) it will be returned as an #rgb hex value ( #ffffff )","title":"Colors (or Colours)"},{"location":"colors/#color-names","text":"Some color names can be given as strings, for example white black red green blue yellow A complete list of color names is available at wiki.tcl.tk/37701","title":"Color names"},{"location":"colors/#rgb-hex-value","text":"A rgb color value must start with a # and 6 characters following, 2 each for the red, green and blue value in hex. Each value must be 00 - ff . Here are some examples: white = #ffffff black = #000000 red = #ff0000 green = #00ff00 blue = #0000ff yellow = #ffff00 You can mix your own color by changing the red, green and blue values. There is a RGB calculator application at https://www.w3schools.com/colors/colors_rgb.asp where you can create your own color and get the #rrggbb value.","title":"rgb hex value"},{"location":"colors/#rgb-list","text":"The (red, green, blue) list color must contain three elements in the order red, green, blue. Each value must be between 0 - 255. Here are some examples: white = (255, 255, 255) black = (0, 0, 0) red = (255, 0, 0) green = (0, 255, 0) blue = (0, 0, 255) yellow = (255, 255, 0)","title":"rgb list"},{"location":"combo/","text":"Combo (Contains a tkinter.OptionMenu object) __init__( self, master, options=[], selected=None, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Combo object displays a drop down box allowing a single option to be selected from a list of options. How do I make one? Create a Combo object like this: from guizero import App, Combo app = App() combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display() Starting parameters When you create a Combo object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options List [] No A list of options to display selected string None No The option to select by default align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the Combo will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on a Combo object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the Combo. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Removes all options from the Combo box destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), item (string) - Insert a new option in the Combo at index remove(option) item (string) Boolean Removes the first option from the Combo. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget select_default() - - Resets the combo box so that the first item is selected show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your Combo object is called combo you would write combo.value . You can set the property (for example combo.value = \"Chicken\" ) or get the value of the property to use (for example print(combo.value) ). Examples Calling a function when the value selected changes You can call a function when the selected value in a Combo object changes. The function you call can take either zero or one argument, if the function takes one argument it will automatically be passed a string containing the currently selected value from the Combo object. from guizero import App, Text, Combo def you_chose(selected_value): if selected_value == \"Tiny goblet\": result.value = \"You chose...wisely\" else: result.value = \"You chose...poorly\" app = App() instructions = Text(app, text=\"Choose a goblet\") combo = Combo(app, options=[\"\", \"Huge golden goblet\", \"Jewel encrusted goblet\", \"Tiny goblet\"], command=you_chose) result = Text(app) app.display()","title":"Combo"},{"location":"combo/#combo","text":"(Contains a tkinter.OptionMenu object) __init__( self, master, options=[], selected=None, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Combo"},{"location":"combo/#what-is-it","text":"The Combo object displays a drop down box allowing a single option to be selected from a list of options.","title":"What is it?"},{"location":"combo/#how-do-i-make-one","text":"Create a Combo object like this: from guizero import App, Combo app = App() combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display()","title":"How do I make one?"},{"location":"combo/#starting-parameters","text":"When you create a Combo object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options List [] No A list of options to display selected string None No The option to select by default align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the Combo will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"combo/#methods","text":"You can call the following methods on a Combo object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the Combo. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Removes all options from the Combo box destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), item (string) - Insert a new option in the Combo at index remove(option) item (string) Boolean Removes the first option from the Combo. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget select_default() - - Resets the combo box so that the first item is selected show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected.","title":"Methods"},{"location":"combo/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your Combo object is called combo you would write combo.value . You can set the property (for example combo.value = \"Chicken\" ) or get the value of the property to use (for example print(combo.value) ).","title":"Properties"},{"location":"combo/#examples","text":"Calling a function when the value selected changes You can call a function when the selected value in a Combo object changes. The function you call can take either zero or one argument, if the function takes one argument it will automatically be passed a string containing the currently selected value from the Combo object. from guizero import App, Text, Combo def you_chose(selected_value): if selected_value == \"Tiny goblet\": result.value = \"You chose...wisely\" else: result.value = \"You chose...poorly\" app = App() instructions = Text(app, text=\"Choose a goblet\") combo = Combo(app, options=[\"\", \"Huge golden goblet\", \"Jewel encrusted goblet\", \"Tiny goblet\"], command=you_chose) result = Text(app) app.display()","title":"Examples"},{"location":"commands/","text":"Commands Widgets in guizero can be given a command when created, which can be used to call a function when the widget is used. By using commands you can make your GUI change and take actions when the user interacts with it, for example by clicking a button, selecting an option or typing a message. Example This code will display hello world when the button is pressed: from guizero import App, Text, PushButton def say_hello(): text.value = \"hello world\" app = App() text = Text(app) button = PushButton(app, command=say_hello) app.display()","title":"Commands"},{"location":"commands/#commands","text":"Widgets in guizero can be given a command when created, which can be used to call a function when the widget is used. By using commands you can make your GUI change and take actions when the user interacts with it, for example by clicking a button, selecting an option or typing a message.","title":"Commands"},{"location":"commands/#example","text":"This code will display hello world when the button is pressed: from guizero import App, Text, PushButton def say_hello(): text.value = \"hello world\" app = App() text = Text(app) button = PushButton(app, command=say_hello) app.display()","title":"Example"},{"location":"contributing/","text":"Contributing Contributions are very welcome; be that changes, bug fixing, issue resolution or support. Issues All issues should be raised on github.com/lawsie/guizero/issues Code When providing code changes please: use the dev branch as the base for all changes create a single pull request for each fix / addition follow the existing coding style provide documentation for all changes as markdown in /docs-src provide tests for all changes in /test","title":"Notes"},{"location":"contributing/#contributing","text":"Contributions are very welcome; be that changes, bug fixing, issue resolution or support.","title":"Contributing"},{"location":"contributing/#issues","text":"All issues should be raised on github.com/lawsie/guizero/issues","title":"Issues"},{"location":"contributing/#code","text":"When providing code changes please: use the dev branch as the base for all changes create a single pull request for each fix / addition follow the existing coding style provide documentation for all changes as markdown in /docs-src provide tests for all changes in /test","title":"Code"},{"location":"deployment/","text":"Deploy Notes on how to deploy guizero (on Windows). Prepare Update version number in guizero\\__init__.py Update version number in docs-src\\docs\\about.md Update version number for Windows MSI installer in docs-src\\docs\\index.md Update changelog.md in docs Python library Install locally: cd guizero python setup.py install Build for deployment: cd guizero python setup.py sdist python setup.py bdist_wheel python setup.py bdist_msi --plat-name=amd64 python setup.py bdist_msi --plat-name=win32 Upload to pypi: cd guizero twine upload dist/* --skip-existing Documents Build: cd guizero/docs-src mkdocs build Copy to docs : cd guizero xcopy docs-src\\site\\* docs /E Promote and tag release on github Push all changes to master . Create a new release on github named 0.0.0 . Upload Windows MSI installers named guizero-0.0.0.amd64.msi and guizero-0.0.0.win32.msi to the release.","title":"Deploying"},{"location":"deployment/#deploy","text":"Notes on how to deploy guizero (on Windows).","title":"Deploy"},{"location":"deployment/#prepare","text":"Update version number in guizero\\__init__.py Update version number in docs-src\\docs\\about.md Update version number for Windows MSI installer in docs-src\\docs\\index.md Update changelog.md in docs","title":"Prepare"},{"location":"deployment/#python-library","text":"Install locally: cd guizero python setup.py install Build for deployment: cd guizero python setup.py sdist python setup.py bdist_wheel python setup.py bdist_msi --plat-name=amd64 python setup.py bdist_msi --plat-name=win32 Upload to pypi: cd guizero twine upload dist/* --skip-existing","title":"Python library"},{"location":"deployment/#documents","text":"Build: cd guizero/docs-src mkdocs build Copy to docs : cd guizero xcopy docs-src\\site\\* docs /E","title":"Documents"},{"location":"deployment/#promote-and-tag-release-on-github","text":"Push all changes to master . Create a new release on github named 0.0.0 . Upload Windows MSI installers named guizero-0.0.0.amd64.msi and guizero-0.0.0.win32.msi to the release.","title":"Promote and tag release on github"},{"location":"development/","text":"Development Notes on how to develop guizero (on Windows). Setup Upgrade pip: python.exe -m pip install pip --upgrade Install / upgrade pre-requisites: pip install mkdocs wheel twine virtualenv pytest pillow --upgrade Python library Create a virtual environment (not essential, but a good idea!): virtualenv guizero-[versionno] cd guizero-[versionno] Activate your virtual environment: Scripts\\activate Checkout and install guizero for development: git clone https://github.com/lawsie/guizero cd guizero git checkout dev python setup.py develop When you have finished your development, deactivate your virtual environment: Scripts\\deactivate Tests To run the automated tests: cd guizero\\test pytest -v If running the tests inside a virtual environment you will need to install pytest in that virtual environment. pip install pytest Note - tkinter can error when running the tests usually when the interpreter doesn't start properly, it doesn't seem to like being initialised and destroyed hundreds of times, I suspect a file locking issue as you don't see the problem on Linux. So sometimes you might get a test fail with an error like This probably means that tk wasn't installed properly. . Just re-run the last failed errors! pytest --lf -v Documents Test documents by serving up MkDocs: cd guizero\\docs-src mkdocs serve Open http://127.0.0.1:8000/","title":"Developing"},{"location":"development/#development","text":"Notes on how to develop guizero (on Windows).","title":"Development"},{"location":"development/#setup","text":"Upgrade pip: python.exe -m pip install pip --upgrade Install / upgrade pre-requisites: pip install mkdocs wheel twine virtualenv pytest pillow --upgrade","title":"Setup"},{"location":"development/#python-library","text":"Create a virtual environment (not essential, but a good idea!): virtualenv guizero-[versionno] cd guizero-[versionno] Activate your virtual environment: Scripts\\activate Checkout and install guizero for development: git clone https://github.com/lawsie/guizero cd guizero git checkout dev python setup.py develop When you have finished your development, deactivate your virtual environment: Scripts\\deactivate","title":"Python library"},{"location":"development/#tests","text":"To run the automated tests: cd guizero\\test pytest -v If running the tests inside a virtual environment you will need to install pytest in that virtual environment. pip install pytest Note - tkinter can error when running the tests usually when the interpreter doesn't start properly, it doesn't seem to like being initialised and destroyed hundreds of times, I suspect a file locking issue as you don't see the problem on Linux. So sometimes you might get a test fail with an error like This probably means that tk wasn't installed properly. . Just re-run the last failed errors! pytest --lf -v","title":"Tests"},{"location":"development/#documents","text":"Test documents by serving up MkDocs: cd guizero\\docs-src mkdocs serve Open http://127.0.0.1:8000/","title":"Documents"},{"location":"drawing/","text":"Drawing (Contains a tkinter.canvas object) __init__( self, master, width=100, height=100, grid=None, align=None, visible=True, enabled=None) What is it? The Drawing object allows shapes, images and text to be created. How do I make one? Create a Drawing object and draw a blue rectangle 50x50 pixels like this: from guizero import App, Drawing app = App() drawing = Drawing(app) drawing.rectangle(10, 10, 60, 60, color=\"blue\") app.display() Starting parameters When you create a Drawing object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: drawing = Drawing(app, height=300, width=300) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master Methods You can call the following methods on a Drawing object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the drawing delete() id (int) - - Deletes an \"object\" (line, triangle, image, etc) from the drawing. destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(self, x, y, image, width=None, height=None): x (int), y (int), image (str), width (int), height (int) Id Inserts an image into the drawing at the specified position and returns the id of the image created. line(x1, y1, x2, y2, color=\"black\", width=1) x1 (int), y1 (int), x2 (int), y2 (int), color (str), width (int) Id Draws a line between 2 points and returns the id of the line created. oval(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws an oval between 2 points and returns the id of the shape created. polygon(*coords, color=\"black\", outline=False, outline_color=\"black\") coords (list int), color (str), outline (int), outline_color (str) Id Draws a polygon between any number of coordinates passed as pairs of x, y and returns the id of the shape created. rectangle(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws a rectangle between 2 points and returns the id of the shape created. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden text(x, y, text, color=\"black\", font=None, size=None, max_width=None) x (int), y (int), text (str), color (str), font (str), size (str), max_width (int) Id Inserts text into the drawing at the specified position and returns the id of the shape created. triangle(x1, y1, x2, y2, x3, y3, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), x3 (int), y3 (int), color (str), outline (int), outline_color (str) Id Draws a triangle between 3 points and returns the id of the shape created. update_command(command) command (function name) - Updates the function to call when a different option is selected. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" Refer to a property as .property . For example, if your Drawing object is called drawing you would write drawing.bg . You can set the property (for example drawing.bg = \"blue\" ) or get the value of the property to use (for example print(drawing.bg) ). Examples Draw a robot face Use a rectangle for the face, ovals for the eyes, a triangle for the nose and lines for the mouth. from guizero import App, Drawing a = App() # create drawing object d = Drawing(a, width=220, height=220) d.rectangle(10, 10, 210, 210, color=\"light blue\") d.oval(30, 30, 50, 50, color=\"white\", outline=True) d.oval(170, 30, 190, 50, color=\"white\", outline=True) d.triangle(110, 90, 120, 110, 100, 110, color=\"black\") d.line(50, 180, 50, 160, color=\"red\", width=5) d.line(50, 180, 170, 180, color=\"red\", width=5) d.line(170, 180, 170, 160, color=\"red\", width=5) a.display()","title":"Drawing"},{"location":"drawing/#drawing","text":"(Contains a tkinter.canvas object) __init__( self, master, width=100, height=100, grid=None, align=None, visible=True, enabled=None)","title":"Drawing"},{"location":"drawing/#what-is-it","text":"The Drawing object allows shapes, images and text to be created.","title":"What is it?"},{"location":"drawing/#how-do-i-make-one","text":"Create a Drawing object and draw a blue rectangle 50x50 pixels like this: from guizero import App, Drawing app = App() drawing = Drawing(app) drawing.rectangle(10, 10, 60, 60, color=\"blue\") app.display()","title":"How do I make one?"},{"location":"drawing/#starting-parameters","text":"When you create a Drawing object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: drawing = Drawing(app, height=300, width=300) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master","title":"Starting parameters"},{"location":"drawing/#methods","text":"You can call the following methods on a Drawing object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the drawing delete() id (int) - - Deletes an \"object\" (line, triangle, image, etc) from the drawing. destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(self, x, y, image, width=None, height=None): x (int), y (int), image (str), width (int), height (int) Id Inserts an image into the drawing at the specified position and returns the id of the image created. line(x1, y1, x2, y2, color=\"black\", width=1) x1 (int), y1 (int), x2 (int), y2 (int), color (str), width (int) Id Draws a line between 2 points and returns the id of the line created. oval(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws an oval between 2 points and returns the id of the shape created. polygon(*coords, color=\"black\", outline=False, outline_color=\"black\") coords (list int), color (str), outline (int), outline_color (str) Id Draws a polygon between any number of coordinates passed as pairs of x, y and returns the id of the shape created. rectangle(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws a rectangle between 2 points and returns the id of the shape created. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden text(x, y, text, color=\"black\", font=None, size=None, max_width=None) x (int), y (int), text (str), color (str), font (str), size (str), max_width (int) Id Inserts text into the drawing at the specified position and returns the id of the shape created. triangle(x1, y1, x2, y2, x3, y3, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), x3 (int), y3 (int), color (str), outline (int), outline_color (str) Id Draws a triangle between 3 points and returns the id of the shape created. update_command(command) command (function name) - Updates the function to call when a different option is selected.","title":"Methods"},{"location":"drawing/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" Refer to a property as .property . For example, if your Drawing object is called drawing you would write drawing.bg . You can set the property (for example drawing.bg = \"blue\" ) or get the value of the property to use (for example print(drawing.bg) ).","title":"Properties"},{"location":"drawing/#examples","text":"Draw a robot face Use a rectangle for the face, ovals for the eyes, a triangle for the nose and lines for the mouth. from guizero import App, Drawing a = App() # create drawing object d = Drawing(a, width=220, height=220) d.rectangle(10, 10, 210, 210, color=\"light blue\") d.oval(30, 30, 50, 50, color=\"white\", outline=True) d.oval(170, 30, 190, 50, color=\"white\", outline=True) d.triangle(110, 90, 120, 110, 100, 110, color=\"black\") d.line(50, 180, 50, 160, color=\"red\", width=5) d.line(50, 180, 170, 180, color=\"red\", width=5) d.line(170, 180, 170, 160, color=\"red\", width=5) a.display()","title":"Examples"},{"location":"events/","text":"Events Custom events can be added to guizero widgets to call functions when the user takes the following actions: when clicked - when_clicked when the left mouse button is pressed - when_left_button_pressed when the left mouse button is released - when_left_button_released when the right mouse button is pressed - when_right_button_pressed when the right mouse button is released - when_right_button_released when a key is pressed - when_key_pressed when a key is released - when_key_released when the mouse enters a widget - when_mouse_enters when the mouse leaves a widget - when_mouse_leaves when the mouse is dragged across a widget - when_mouse_dragged Events are set by assigning them to a function: def do_this(): print(\"The widget was clicked\") widget.when_clicked = do_this Event Data The function which is called can also accept a parameter and will be passed data about the event which occured. The event data returned has: widget - the guizero widget which raised the event tk_event - the tkinter event object key - the key which raised the event x - the mouse's x position relative to the widget when the event occured y - the mouse's y position relative to the widget when the event occured display_x - the mouse's x position on the display when the event occured display_y - the mouse's y position on the display when the event occured def clicked(event_data): print(\"widget clicked = \" + event_data.widget) print(\"mouse position = \" + event_data.x + \".\" + event_data.y) widget.when_clicked = clicked Example Highlight a text box widget by changing its background color ( bg ) when the mouse is hovering over it. from guizero import App, TextBox def highlight(): text_box.bg = \"lightblue\" def lowlight(): text_box.bg = \"white\" app = App() text_box = TextBox(app) # When the mouse enters the TextBox text_box.when_mouse_enters = highlight # When the mouse leaves the TextBox text_box.when_mouse_leaves = lowlight app.display()","title":"Events"},{"location":"events/#events","text":"Custom events can be added to guizero widgets to call functions when the user takes the following actions: when clicked - when_clicked when the left mouse button is pressed - when_left_button_pressed when the left mouse button is released - when_left_button_released when the right mouse button is pressed - when_right_button_pressed when the right mouse button is released - when_right_button_released when a key is pressed - when_key_pressed when a key is released - when_key_released when the mouse enters a widget - when_mouse_enters when the mouse leaves a widget - when_mouse_leaves when the mouse is dragged across a widget - when_mouse_dragged Events are set by assigning them to a function: def do_this(): print(\"The widget was clicked\") widget.when_clicked = do_this","title":"Events"},{"location":"events/#event-data","text":"The function which is called can also accept a parameter and will be passed data about the event which occured. The event data returned has: widget - the guizero widget which raised the event tk_event - the tkinter event object key - the key which raised the event x - the mouse's x position relative to the widget when the event occured y - the mouse's y position relative to the widget when the event occured display_x - the mouse's x position on the display when the event occured display_y - the mouse's y position on the display when the event occured def clicked(event_data): print(\"widget clicked = \" + event_data.widget) print(\"mouse position = \" + event_data.x + \".\" + event_data.y) widget.when_clicked = clicked","title":"Event Data"},{"location":"events/#example","text":"Highlight a text box widget by changing its background color ( bg ) when the mouse is hovering over it. from guizero import App, TextBox def highlight(): text_box.bg = \"lightblue\" def lowlight(): text_box.bg = \"white\" app = App() text_box = TextBox(app) # When the mouse enters the TextBox text_box.when_mouse_enters = highlight # When the mouse leaves the TextBox text_box.when_mouse_leaves = lowlight app.display()","title":"Example"},{"location":"gettinghelp/","text":"Getting help You may encounter a problem when using guizero, so here are some ways you can get help to solve your problem. Getting help If you have a question about your guizero program it is a good idea to join a community to ask for support: Raspberry Pi Forums - some people post questions about guizero on these forums and other members of the community step in to help. The creators of guizero periodically check the Python forum. Stack Overflow - a popular site for techy questions Computing at School - a useful site for teachers If you would like to read guides and resources for guizero there are many freely available: Getting started with GUIs - a beginners guide to guizero by the Raspberry Pi Foundation Python guizero video - a series of videos by Devon Schafer on using guizero. Example programs - some example programs to get you going. Using guizero with hardware - Ben Nuttall's projects using guizero combined with hardware Cat name generator - materials for a kids workshop, first run at the Cotswold Jam Name your pet - article on page 42 of Hello World magazine issue 2. Bugs and feature requests Like many Python libraries, guizero has a GitHub repository where you can add issues. These issues come under two headings: You found a bug in guizero You would like to request we consider including a new feature We look at and respond to all issues created on GitHub. However, we ask that you only create issues for bugs and feature requests, rather than support, as we do not have time to answer everything :)","title":"Getting help"},{"location":"gettinghelp/#getting-help","text":"You may encounter a problem when using guizero, so here are some ways you can get help to solve your problem.","title":"Getting help"},{"location":"gettinghelp/#getting-help_1","text":"If you have a question about your guizero program it is a good idea to join a community to ask for support: Raspberry Pi Forums - some people post questions about guizero on these forums and other members of the community step in to help. The creators of guizero periodically check the Python forum. Stack Overflow - a popular site for techy questions Computing at School - a useful site for teachers If you would like to read guides and resources for guizero there are many freely available: Getting started with GUIs - a beginners guide to guizero by the Raspberry Pi Foundation Python guizero video - a series of videos by Devon Schafer on using guizero. Example programs - some example programs to get you going. Using guizero with hardware - Ben Nuttall's projects using guizero combined with hardware Cat name generator - materials for a kids workshop, first run at the Cotswold Jam Name your pet - article on page 42 of Hello World magazine issue 2.","title":"Getting help"},{"location":"gettinghelp/#bugs-and-feature-requests","text":"Like many Python libraries, guizero has a GitHub repository where you can add issues. These issues come under two headings: You found a bug in guizero You would like to request we consider including a new feature We look at and respond to all issues created on GitHub. However, we ask that you only create issues for bugs and feature requests, rather than support, as we do not have time to answer everything :)","title":"Bugs and feature requests"},{"location":"images/","text":"Images Widgets such as Picture and PushButton allow you to use images in your GUI. from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() The types of image (GIF, JPG, PNG, etc) supported depend on how you installed guizero and the setup of your computer. Supported files types All systems support the GIF file type. Windows and Linux also support PNG files. If you installed the addition image features using pip it will also have installed PIL (Python Imaging Library) and you will be able use the majority of commonly used image types. guizero will tell you what file types are supported on your computer using the following code: from guizero import system_config print(system_config.supported_image_types) Operating System PIL NOT available PIL available Windows GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF MacOS GIF GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Linux GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Raspbian GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Resizing When the size of a widget is changed the image will be changed to fit the widget. If the additional image features were installed and PIL is available, the image will be scaled correctly, if not the image will be cropped. Animated GIFs If PIL is installed guizero supports displaying animated GIFs, if not, the GIF will be displayed as a static image.","title":"Images"},{"location":"images/#images","text":"Widgets such as Picture and PushButton allow you to use images in your GUI. from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() The types of image (GIF, JPG, PNG, etc) supported depend on how you installed guizero and the setup of your computer.","title":"Images"},{"location":"images/#supported-files-types","text":"All systems support the GIF file type. Windows and Linux also support PNG files. If you installed the addition image features using pip it will also have installed PIL (Python Imaging Library) and you will be able use the majority of commonly used image types. guizero will tell you what file types are supported on your computer using the following code: from guizero import system_config print(system_config.supported_image_types) Operating System PIL NOT available PIL available Windows GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF MacOS GIF GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Linux GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Raspbian GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF","title":"Supported files types"},{"location":"images/#resizing","text":"When the size of a widget is changed the image will be changed to fit the widget. If the additional image features were installed and PIL is available, the image will be scaled correctly, if not the image will be cropped.","title":"Resizing"},{"location":"images/#animated-gifs","text":"If PIL is installed guizero supports displaying animated GIFs, if not, the GIF will be displayed as a static image.","title":"Animated GIFs"},{"location":"layout/","text":"Layouts The layout of your GUI is how you arrange the widgets in the window. Widgets can be arranged into \"containers\" (e.g. App , Window , Box ) using either of these layouts: auto - where widgets are positioned automatically grid - you specify where in a grid each widget should be positioned The layout is set using the layout parameter of the container, for example: app = App(layout=\"auto\") app = App(layout=\"grid\") If no layout parameter is specified, the default auto layout is used. Auto layout auto is the default layout used when a container is created. All widgets will be arranged in the order they are created and aligned to the centre. For example, the following code will create two Text widgets, one on top of the other. from guizero import App, Text app = App() text_1 = Text(app, text=\"on top\") text_2 = Text(app, text=\"below\") app.display() Aligning Widgets can be aligned to either the top , bottom , left or right , using the align property when created. Aligning a widget will cause it to be \"stuck\" to that side of the container, for example: from guizero import App, Text app = App() top_text = Text(app, text=\"at the top\", align=\"top\") bottom_text = Text(app, text=\"at the bottom\", align=\"bottom\") left_text = Text(app, text=\"to the left\", align=\"left\") right_text = Text(app, text=\"to the right\", align=\"right\") app.display() By aligning multiple widgets to the same side of the container, widgets can be made to stack together: from guizero import App, Text, TextBox, PushButton app = App() text = Text(app, text=\"label\", align=\"left\") text_box = TextBox(app, text=\"enter text\", align=\"left\") button = PushButton(app, text=\"submit\", align=\"left\") app.display() The widgets will stack in the order they are created, so the widget created first will be closest to the edge in the direction specified. Filling Widgets can also be made to \"fill\" all available space by setting the width and height parameters to fill . Here are some examples: A TextBox could span the entire width of the container: from guizero import App, TextBox app = App() text_box = TextBox(app, text=\"enter text\", width=\"fill\") app.display() Or a ListBox could fill the left hand side by using fill for the height and align to the left : from guizero import App, ListBox app = App() list_box = ListBox(app, items=[\"a list\"], height=\"fill\", align=\"left\") app.display() Using fill for the width and the height will make a widget use all of the available space: from guizero import App, PushButton app = App() button = PushButton(app, width=\"fill\", height=\"fill\") app.display() When multiple widgets use fill , the Window Manager (operating system) will distribute the space accordingly between all the widgets which have requested to fill it. from guizero import App, ListBox, PushButton app = App() list_box = ListBox(app, items=[\"a list\", \"of items\", \"yay\"], height=\"fill\", align=\"left\") button = PushButton(app, width=\"fill\", height=\"fill\", align=\"right\") app.display() Note : Using fill may not always have the effect you are expecting, as it is up to the operating system to distribute screen space. Grid layout The grid layout allows you to position widgets into a virtual grid. When you create a widget you will need to pass an extra parameter called grid which is a list containing [x,y] coordinates for where you want the widget to appear, like this: app = App(layout=\"grid\") text = Text(app, text=\"Hello world\", grid=[0,1]) There is no need to specify the width or height of the grid you want - it will expand depending on the coordinates you provide with each widget. However, grid cells containing no objects will have no height or width. This is really useful when creating GUIs where you want widgets to line up. For example, you could create a number keypad: from guizero import App, PushButton app = App(layout=\"grid\") button1 = PushButton(app, text=\"1\", grid=[0,0]) button2 = PushButton(app, text=\"2\", grid=[1,0]) button3 = PushButton(app, text=\"3\", grid=[2,0]) button4 = PushButton(app, text=\"4\", grid=[0,1]) button5 = PushButton(app, text=\"5\", grid=[1,1]) button6 = PushButton(app, text=\"6\", grid=[2,1]) button7 = PushButton(app, text=\"7\", grid=[0,2]) button8 = PushButton(app, text=\"8\", grid=[1,2]) button9 = PushButton(app, text=\"9\", grid=[2,2]) button0 = PushButton(app, text=\"0\", grid=[1,3]) app.display() You can also align widgets within the grid, which is useful when you are creating a form: from guizero import App, Text, TextBox app = App(layout=\"grid\") name_label = Text(app, text=\"Name\", grid=[0,0], align=\"left\") name = TextBox(app, grid=[1,0]) surname_label = Text(app, text=\"Surname\", grid=[0,1], align=\"left\") surname = TextBox(app, grid=[1,1]) dob_label = Text(app, text=\"Date of Birth\", grid=[0,2], align=\"left\") dob = TextBox(app, grid=[1,2]) app.display() Spanning columns or rows Widgets can be made to span multiple columns or rows by specifying the span within the grid parameter. These are optional, but if specified both must be included using the format [x,y,xspan,yspan] . The example below shows a Text widget located at 0,1 and spanning two columns (x) and one row (y): text = Text(app, text=\"Hello world\", grid=[0,1,2,1]) This layout method can be used to include widgets of different sizes arranged alongside each other. from guizero import App, Picture app = App(layout=\"grid\") picture1 = Picture(app, image=\"std1.gif\", grid=[0,0]) picture2 = Picture(app, image=\"std2.gif\", grid=[1,0]) picture3 = Picture(app, image=\"tall1.gif\", grid=[2,0,1,2]) picture4 = Picture(app, image=\"wide1.gif\", grid=[0,1,2,1]) app.display() Boxes By using a Box widget you can segment your GUI into different sections allowing you to lay out your user interface in any way you want. ( Code for example above ) If you wanted to create a title in the top left hand corner of your GUI, you could use a Box which fills the top of the App and put a Text widget inside aligned to the left . from guizero import App, Box, Text app = App() title_box = Box(app, width=\"fill\", align=\"top\") title = Text(title_box, text=\"title\", align=\"left\") app.display() You may find it easier to design your layout if your Boxes have borders, which can be done by setting the border parameter on Box to True . title_box = Box(app, width=\"fill\", align=\"top\", border=True) A similar method can be used to put \"OK\" and \"Cancel\" buttons at the bottom right of the GUI. Remember that the widgets will get stacked on the right in order of creation, so the cancel button is created first. from guizero import App, Box, PushButton app = App() buttons_box = Box(app, width=\"fill\", align=\"bottom\") cancel = PushButton(buttons_box, text=\"Cancel\", align=\"right\") ok = PushButton(buttons_box, text=\"OK\", align=\"right\") app.display() Note : You can put a Box inside another Box , allowing you to layer boxes and position your widgets. Tip : When creating a GUI you may find it easier to design it first on paper, noting where your boxes will be positioned. Unfortunately, whilst you can put one box inside another box, guizero does not support mailing it to yourself, nor smashing it with a hammer ;)","title":"Layouts"},{"location":"layout/#layouts","text":"The layout of your GUI is how you arrange the widgets in the window. Widgets can be arranged into \"containers\" (e.g. App , Window , Box ) using either of these layouts: auto - where widgets are positioned automatically grid - you specify where in a grid each widget should be positioned The layout is set using the layout parameter of the container, for example: app = App(layout=\"auto\") app = App(layout=\"grid\") If no layout parameter is specified, the default auto layout is used.","title":"Layouts"},{"location":"layout/#auto-layout","text":"auto is the default layout used when a container is created. All widgets will be arranged in the order they are created and aligned to the centre. For example, the following code will create two Text widgets, one on top of the other. from guizero import App, Text app = App() text_1 = Text(app, text=\"on top\") text_2 = Text(app, text=\"below\") app.display()","title":"Auto layout"},{"location":"layout/#aligning","text":"Widgets can be aligned to either the top , bottom , left or right , using the align property when created. Aligning a widget will cause it to be \"stuck\" to that side of the container, for example: from guizero import App, Text app = App() top_text = Text(app, text=\"at the top\", align=\"top\") bottom_text = Text(app, text=\"at the bottom\", align=\"bottom\") left_text = Text(app, text=\"to the left\", align=\"left\") right_text = Text(app, text=\"to the right\", align=\"right\") app.display() By aligning multiple widgets to the same side of the container, widgets can be made to stack together: from guizero import App, Text, TextBox, PushButton app = App() text = Text(app, text=\"label\", align=\"left\") text_box = TextBox(app, text=\"enter text\", align=\"left\") button = PushButton(app, text=\"submit\", align=\"left\") app.display() The widgets will stack in the order they are created, so the widget created first will be closest to the edge in the direction specified.","title":"Aligning"},{"location":"layout/#filling","text":"Widgets can also be made to \"fill\" all available space by setting the width and height parameters to fill . Here are some examples: A TextBox could span the entire width of the container: from guizero import App, TextBox app = App() text_box = TextBox(app, text=\"enter text\", width=\"fill\") app.display() Or a ListBox could fill the left hand side by using fill for the height and align to the left : from guizero import App, ListBox app = App() list_box = ListBox(app, items=[\"a list\"], height=\"fill\", align=\"left\") app.display() Using fill for the width and the height will make a widget use all of the available space: from guizero import App, PushButton app = App() button = PushButton(app, width=\"fill\", height=\"fill\") app.display() When multiple widgets use fill , the Window Manager (operating system) will distribute the space accordingly between all the widgets which have requested to fill it. from guizero import App, ListBox, PushButton app = App() list_box = ListBox(app, items=[\"a list\", \"of items\", \"yay\"], height=\"fill\", align=\"left\") button = PushButton(app, width=\"fill\", height=\"fill\", align=\"right\") app.display() Note : Using fill may not always have the effect you are expecting, as it is up to the operating system to distribute screen space.","title":"Filling"},{"location":"layout/#grid-layout","text":"The grid layout allows you to position widgets into a virtual grid. When you create a widget you will need to pass an extra parameter called grid which is a list containing [x,y] coordinates for where you want the widget to appear, like this: app = App(layout=\"grid\") text = Text(app, text=\"Hello world\", grid=[0,1]) There is no need to specify the width or height of the grid you want - it will expand depending on the coordinates you provide with each widget. However, grid cells containing no objects will have no height or width. This is really useful when creating GUIs where you want widgets to line up. For example, you could create a number keypad: from guizero import App, PushButton app = App(layout=\"grid\") button1 = PushButton(app, text=\"1\", grid=[0,0]) button2 = PushButton(app, text=\"2\", grid=[1,0]) button3 = PushButton(app, text=\"3\", grid=[2,0]) button4 = PushButton(app, text=\"4\", grid=[0,1]) button5 = PushButton(app, text=\"5\", grid=[1,1]) button6 = PushButton(app, text=\"6\", grid=[2,1]) button7 = PushButton(app, text=\"7\", grid=[0,2]) button8 = PushButton(app, text=\"8\", grid=[1,2]) button9 = PushButton(app, text=\"9\", grid=[2,2]) button0 = PushButton(app, text=\"0\", grid=[1,3]) app.display() You can also align widgets within the grid, which is useful when you are creating a form: from guizero import App, Text, TextBox app = App(layout=\"grid\") name_label = Text(app, text=\"Name\", grid=[0,0], align=\"left\") name = TextBox(app, grid=[1,0]) surname_label = Text(app, text=\"Surname\", grid=[0,1], align=\"left\") surname = TextBox(app, grid=[1,1]) dob_label = Text(app, text=\"Date of Birth\", grid=[0,2], align=\"left\") dob = TextBox(app, grid=[1,2]) app.display()","title":"Grid layout"},{"location":"layout/#spanning-columns-or-rows","text":"Widgets can be made to span multiple columns or rows by specifying the span within the grid parameter. These are optional, but if specified both must be included using the format [x,y,xspan,yspan] . The example below shows a Text widget located at 0,1 and spanning two columns (x) and one row (y): text = Text(app, text=\"Hello world\", grid=[0,1,2,1]) This layout method can be used to include widgets of different sizes arranged alongside each other. from guizero import App, Picture app = App(layout=\"grid\") picture1 = Picture(app, image=\"std1.gif\", grid=[0,0]) picture2 = Picture(app, image=\"std2.gif\", grid=[1,0]) picture3 = Picture(app, image=\"tall1.gif\", grid=[2,0,1,2]) picture4 = Picture(app, image=\"wide1.gif\", grid=[0,1,2,1]) app.display()","title":"Spanning columns or rows"},{"location":"layout/#boxes","text":"By using a Box widget you can segment your GUI into different sections allowing you to lay out your user interface in any way you want. ( Code for example above ) If you wanted to create a title in the top left hand corner of your GUI, you could use a Box which fills the top of the App and put a Text widget inside aligned to the left . from guizero import App, Box, Text app = App() title_box = Box(app, width=\"fill\", align=\"top\") title = Text(title_box, text=\"title\", align=\"left\") app.display() You may find it easier to design your layout if your Boxes have borders, which can be done by setting the border parameter on Box to True . title_box = Box(app, width=\"fill\", align=\"top\", border=True) A similar method can be used to put \"OK\" and \"Cancel\" buttons at the bottom right of the GUI. Remember that the widgets will get stacked on the right in order of creation, so the cancel button is created first. from guizero import App, Box, PushButton app = App() buttons_box = Box(app, width=\"fill\", align=\"bottom\") cancel = PushButton(buttons_box, text=\"Cancel\", align=\"right\") ok = PushButton(buttons_box, text=\"OK\", align=\"right\") app.display() Note : You can put a Box inside another Box , allowing you to layer boxes and position your widgets. Tip : When creating a GUI you may find it easier to design it first on paper, noting where your boxes will be positioned. Unfortunately, whilst you can put one box inside another box, guizero does not support mailing it to yourself, nor smashing it with a hammer ;)","title":"Boxes"},{"location":"listbox/","text":"ListBox (Contains a tkinter.Listbox object) __init__( self, master, items=None, selected=None, command=None, grid=None, align=None, visible=True, enabled=None, multiselect=False, scrollbar=False, width=None, height=None) What is it? The ListBox object displays a list of items from which either single or multiple items can be selected. How do I make one? Create a ListBox object like this: from guizero import App, ListBox app = App() listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display() Starting parameters When you create a ListBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) If you want the ListBox to allow multiple items to be selected you must set the multiselect optional parameter to True : listbox = ListBox(app, multiselect=True) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs selected string or List None No The item or items to select by default items List - Yes A list of items to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the ListBox will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiselect boolean False No If the widget should allow multiple items to be selected. scrollbar boolean False No If the widget should have a verticle scrollbar. width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" Methods You can call the following methods on a ListBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(item) item (string) - Appends a new item to the end of the ListBox. cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears all the items in a ListBox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, item) index (int), item (string) - Insert a new item in the ListBox at index remove(item) item (string) Boolean Removes the first item from the ListBox. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" items List Returns a list of items in the ListBox master App or Box The container to which this widget belongs value string Sets or returns the items selected in a ListBox. Returns None if 0 items are selected. If the ListBox is a not multiselect , value is the item selected, if the ListBox is a multiselect , value is a list of items selected. visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your ListBox object is called listbox you would write listbox.value . You can set the property (for example listbox.value = \"Chicken\" ) or get the value of the property to use (for example print(listbox.value) ). Examples Select a text color from a ListBox When an item in the ListBox is selected a function will be called to change the color of the text. from guizero import App, ListBox, Text def change_color(value): t.text_color = value a = App() t = Text(a, text=\"Its a ListBox\", color=\"black\") listbox = ListBox( a, items=[\"red\", \"green\", \"blue\", \"yellow\", \"purple\", \"turquoise\", \"pink\", \"orange\", \"black\", \"brown\", \"cyan\"], selected=\"black\", command=change_color, scrollbar=True) a.display()","title":"ListBox"},{"location":"listbox/#listbox","text":"(Contains a tkinter.Listbox object) __init__( self, master, items=None, selected=None, command=None, grid=None, align=None, visible=True, enabled=None, multiselect=False, scrollbar=False, width=None, height=None)","title":"ListBox"},{"location":"listbox/#what-is-it","text":"The ListBox object displays a list of items from which either single or multiple items can be selected.","title":"What is it?"},{"location":"listbox/#how-do-i-make-one","text":"Create a ListBox object like this: from guizero import App, ListBox app = App() listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display()","title":"How do I make one?"},{"location":"listbox/#starting-parameters","text":"When you create a ListBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) If you want the ListBox to allow multiple items to be selected you must set the multiselect optional parameter to True : listbox = ListBox(app, multiselect=True) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs selected string or List None No The item or items to select by default items List - Yes A list of items to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the ListBox will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiselect boolean False No If the widget should allow multiple items to be selected. scrollbar boolean False No If the widget should have a verticle scrollbar. width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\"","title":"Starting parameters"},{"location":"listbox/#methods","text":"You can call the following methods on a ListBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(item) item (string) - Appends a new item to the end of the ListBox. cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears all the items in a ListBox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, item) index (int), item (string) - Insert a new item in the ListBox at index remove(item) item (string) Boolean Removes the first item from the ListBox. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected.","title":"Methods"},{"location":"listbox/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" items List Returns a list of items in the ListBox master App or Box The container to which this widget belongs value string Sets or returns the items selected in a ListBox. Returns None if 0 items are selected. If the ListBox is a not multiselect , value is the item selected, if the ListBox is a multiselect , value is a list of items selected. visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" text_size int The size of the text text_color color The colour of the text Refer to a property as .property . For example, if your ListBox object is called listbox you would write listbox.value . You can set the property (for example listbox.value = \"Chicken\" ) or get the value of the property to use (for example print(listbox.value) ).","title":"Properties"},{"location":"listbox/#examples","text":"Select a text color from a ListBox When an item in the ListBox is selected a function will be called to change the color of the text. from guizero import App, ListBox, Text def change_color(value): t.text_color = value a = App() t = Text(a, text=\"Its a ListBox\", color=\"black\") listbox = ListBox( a, items=[\"red\", \"green\", \"blue\", \"yellow\", \"purple\", \"turquoise\", \"pink\", \"orange\", \"black\", \"brown\", \"cyan\"], selected=\"black\", command=change_color, scrollbar=True) a.display()","title":"Examples"},{"location":"menubar/","text":"MenuBar (Contains a tkinter.Menu object) __init__( self, master, toplevel, options) What is it? The MenuBar object displays a menu at the top of the screen, with each menu option leading to a submenu. How do I make one? Create a MenuBar object like this: from guizero import App, MenuBar def file_function(): print(\"File option\") def edit_function(): print(\"Edit option\") app = App() menubar = MenuBar(app, toplevel=[\"File\", \"Edit\"], options=[ [ [\"File option 1\", file_function], [\"File option 2\", file_function] ], [ [\"Edit option 1\", edit_function], [\"Edit option 2\", edit_function] ] ]) app.display() Starting parameters When you create a MenuBar object you must specify all of the parameters. Parameter Takes Default Compulsory Description master App - Yes The container to which this widget belongs toplevel list - Yes A list of top level menu items options 3D list - Yes A list of submenus, with each submenu being a list of options and each option being a text/command pair. See notes above for more details. The toplevel parameter should be a list of options you wish to display on the menu. In the example, the toplevel options are File and Edit: The options parameter should be a 3D List containing lists of submenu items, which are themselves lists. The elements in the list correspond to the elements in the toplevel list, so the first list of submenu items provided in options will be the submenu for the first menu heading provided in toplevel and so on. The menu item sub-sublists within options should contain pairs consisting of the text to display on the menu and the function to call when that option is selected. In this example, the text \"File option 1\" is displayed and the function file_function is called if this option is clicked on. [\"File option 1\", file_function] The MenuBar is never displayed on a grid so there are no grid or alignment parameters. Methods You can call the following methods on an MenuBar object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. Properties You can set and get the following properties: Method Data type Description master App The App object to which this MenuBar belongs","title":"MenuBar"},{"location":"menubar/#menubar","text":"(Contains a tkinter.Menu object) __init__( self, master, toplevel, options)","title":"MenuBar"},{"location":"menubar/#what-is-it","text":"The MenuBar object displays a menu at the top of the screen, with each menu option leading to a submenu.","title":"What is it?"},{"location":"menubar/#how-do-i-make-one","text":"Create a MenuBar object like this: from guizero import App, MenuBar def file_function(): print(\"File option\") def edit_function(): print(\"Edit option\") app = App() menubar = MenuBar(app, toplevel=[\"File\", \"Edit\"], options=[ [ [\"File option 1\", file_function], [\"File option 2\", file_function] ], [ [\"Edit option 1\", edit_function], [\"Edit option 2\", edit_function] ] ]) app.display()","title":"How do I make one?"},{"location":"menubar/#starting-parameters","text":"When you create a MenuBar object you must specify all of the parameters. Parameter Takes Default Compulsory Description master App - Yes The container to which this widget belongs toplevel list - Yes A list of top level menu items options 3D list - Yes A list of submenus, with each submenu being a list of options and each option being a text/command pair. See notes above for more details. The toplevel parameter should be a list of options you wish to display on the menu. In the example, the toplevel options are File and Edit: The options parameter should be a 3D List containing lists of submenu items, which are themselves lists. The elements in the list correspond to the elements in the toplevel list, so the first list of submenu items provided in options will be the submenu for the first menu heading provided in toplevel and so on. The menu item sub-sublists within options should contain pairs consisting of the text to display on the menu and the function to call when that option is selected. In this example, the text \"File option 1\" is displayed and the function file_function is called if this option is clicked on. [\"File option 1\", file_function] The MenuBar is never displayed on a grid so there are no grid or alignment parameters.","title":"Starting parameters"},{"location":"menubar/#methods","text":"You can call the following methods on an MenuBar object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor.","title":"Methods"},{"location":"menubar/#properties","text":"You can set and get the following properties: Method Data type Description master App The App object to which this MenuBar belongs","title":"Properties"},{"location":"multiple_windows/","text":"Multiple Windows A guizero application should only have have one single App object - this is the main window and controller of your program. If you want to create a second (or 3rd, 4th, 5th) window, your program should use a Window object. A Second window When you create a second Window you need to pass it the App , just like when you create a widget: from guizero import App, Window app = App(title=\"Main window\") window = Window(app, title=\"Second window\") app.display() Adding widgets to the second window is the same as adding them to an App . You tell the widget which window it will be in by passing it the name of the Window : from guizero import App, Window, Text app = App(title=\"Main window\") window = Window(app, title=\"Second window\") text = Text(window, text=\"This text will show up in the second window\") app.display() Opening and closing windows When a Window object is created it is immediately displayed on the screen. You can control whether a window is visible or not using the show() and hide() methods. This code creates a window which is shown when a button on the App is clicked and closed when a button is clicked in the Window . from guizero import App, Window, PushButton def open_window(): window.show() def close_window(): window.hide() app = App(title=\"Main window\") window = Window(app, title=\"Second window\") window.hide() open_button = PushButton(app, text=\"Open\", command=open_window) close_button = PushButton(window, text=\"Close\", command=close_window) app.display() Modal windows When a window is opened using show() it opens side by side with the main window, and both windows can be used at the same time. A \"modal\" window prevents the other windows in the application being used until it is closed. To create a modal window, you can pass True to the optional wait parameter of show . This will force all other windows to wait until this window is closed before they can be used. def open_window(): window.show(wait=True)","title":"Multiple windows"},{"location":"multiple_windows/#multiple-windows","text":"A guizero application should only have have one single App object - this is the main window and controller of your program. If you want to create a second (or 3rd, 4th, 5th) window, your program should use a Window object.","title":"Multiple Windows"},{"location":"multiple_windows/#a-second-window","text":"When you create a second Window you need to pass it the App , just like when you create a widget: from guizero import App, Window app = App(title=\"Main window\") window = Window(app, title=\"Second window\") app.display() Adding widgets to the second window is the same as adding them to an App . You tell the widget which window it will be in by passing it the name of the Window : from guizero import App, Window, Text app = App(title=\"Main window\") window = Window(app, title=\"Second window\") text = Text(window, text=\"This text will show up in the second window\") app.display()","title":"A Second window"},{"location":"multiple_windows/#opening-and-closing-windows","text":"When a Window object is created it is immediately displayed on the screen. You can control whether a window is visible or not using the show() and hide() methods. This code creates a window which is shown when a button on the App is clicked and closed when a button is clicked in the Window . from guizero import App, Window, PushButton def open_window(): window.show() def close_window(): window.hide() app = App(title=\"Main window\") window = Window(app, title=\"Second window\") window.hide() open_button = PushButton(app, text=\"Open\", command=open_window) close_button = PushButton(window, text=\"Close\", command=close_window) app.display()","title":"Opening and closing windows"},{"location":"multiple_windows/#modal-windows","text":"When a window is opened using show() it opens side by side with the main window, and both windows can be used at the same time. A \"modal\" window prevents the other windows in the application being used until it is closed. To create a modal window, you can pass True to the optional wait parameter of show . This will force all other windows to wait until this window is closed before they can be used. def open_window(): window.show(wait=True)","title":"Modal windows"},{"location":"picture/","text":"Picture (Contains a tkinter.Label object) __init__( self, master, image=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Picture object displays an image. How do I make one? Create a Picture object like this: from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() You must specify the correct path to the image. The image in the example is in the same directory as the program. If the image is in a different directory, specify a relative path, for example if the picture is in a subfolder called images you would write: picture = Picture(app, image=\"images/test.gif\") Image support Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use with Picture . By default GIF and PNG are supported, except macOS which only supports GIF. Starting parameters When you create a Picture object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: picture = Picture(app, image=\"test.gif\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels height size None No Set the height of the widget in pixels Methods You can call the following methods on a Picture object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels image string The file path, tkinter.PhotoImage or PIL.Image you wish to display master App or Box The container to which this widget belongs value string The file path, tkinter.PhotoImage or PIL.Image you wish to display visible boolean If this widget is visible width size Set the width of the widget in pixels Refer to a property as .property . For example, if your Picture object is called picture you would write picture.value . You can set the property (for example picture.value = \"star.gif\" ) or get the value of the property to use (for example print(picture.value) ).","title":"Picture"},{"location":"picture/#picture","text":"(Contains a tkinter.Label object) __init__( self, master, image=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Picture"},{"location":"picture/#what-is-it","text":"The Picture object displays an image.","title":"What is it?"},{"location":"picture/#how-do-i-make-one","text":"Create a Picture object like this: from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() You must specify the correct path to the image. The image in the example is in the same directory as the program. If the image is in a different directory, specify a relative path, for example if the picture is in a subfolder called images you would write: picture = Picture(app, image=\"images/test.gif\")","title":"How do I make one?"},{"location":"picture/#image-support","text":"Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use with Picture . By default GIF and PNG are supported, except macOS which only supports GIF.","title":"Image support"},{"location":"picture/#starting-parameters","text":"When you create a Picture object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: picture = Picture(app, image=\"test.gif\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels height size None No Set the height of the widget in pixels","title":"Starting parameters"},{"location":"picture/#methods","text":"You can call the following methods on a Picture object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden","title":"Methods"},{"location":"picture/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels image string The file path, tkinter.PhotoImage or PIL.Image you wish to display master App or Box The container to which this widget belongs value string The file path, tkinter.PhotoImage or PIL.Image you wish to display visible boolean If this widget is visible width size Set the width of the widget in pixels Refer to a property as .property . For example, if your Picture object is called picture you would write picture.value . You can set the property (for example picture.value = \"star.gif\" ) or get the value of the property to use (for example print(picture.value) ).","title":"Properties"},{"location":"pushbutton/","text":"PushButton (Contains a tkinter.Button object) __init__( self, master, command=None, args=None, text=\"Button\", image=None, pady=10, padx=10, grid=None, align=None, icon=None, visible=True, enabled=None, width=None, height=None) What is it? The PushButton object displays a button with text or an image, which calls a function when pressed. How do I make one? Create a PushButton object like this: from guizero import App, PushButton def do_nothing(): print(\"Button was pressed\") app = App() button = PushButton(app, command=do_nothing) app.display() Create a picture PushButton with an image like this: from guizero import App, PushButton def do_nothing(): print(\"A picture button was pressed\") app = App() button = PushButton(app, image=\"button.gif\", command=do_nothing) app.display() Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use for PushButton . By default GIF and PNG are supported, except macOS which only supports GIF. Starting parameters When you create a PushButton object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: button = PushButton(app) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs command function name None - The name of a function to call when the button is pressed. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display. If both an image and text are specified, the image will override the text. padx int 10 - How much horizontal padding to add between the text/icon and the edge of the button. pady int 10 - How much vertical padding to add between the text/icon and the edge of the button. text string \"Button\" - The text to display on the button visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or pixels if its an image button or to \"fill\" height size None No Set the height of the widget in characters or pixels if its an image button or to \"fill\" Methods You can call the following methods on a PushButton object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(image_source) image_source (string) - The file path, tkinter.PhotoImage or PIL.Image you wish to display. padding(padx, pady) padx (int), pady(int) - Sets the amount of x (horizontal) and y (vertical) padding between the text/icon and the edge of the button repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Changes the state of the button to the opposite of its current state - if it is currently enabled, disable it and vice versa. update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the button is pressed . Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text on the button grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or pixels if its an image button or to \"fill\" master App or Box The container to which this widget belongs text string The text on the button text_color color The colour of the text on the button text_size int The size of the text on the button value int Returns 1 when the button is pressed, 0 if the button is released visible boolean If this widget is visible width size Set the width of the widget in characters or pixels if its an image button or to \"fill\" Refer to a property as .property . For example, if your PushButton object is called button you would write button.value . You can set the property (for example button.bg = \"red\" ) or get the value of the property to use (for example print(button.bg) ).","title":"PushButton"},{"location":"pushbutton/#pushbutton","text":"(Contains a tkinter.Button object) __init__( self, master, command=None, args=None, text=\"Button\", image=None, pady=10, padx=10, grid=None, align=None, icon=None, visible=True, enabled=None, width=None, height=None)","title":"PushButton"},{"location":"pushbutton/#what-is-it","text":"The PushButton object displays a button with text or an image, which calls a function when pressed.","title":"What is it?"},{"location":"pushbutton/#how-do-i-make-one","text":"Create a PushButton object like this: from guizero import App, PushButton def do_nothing(): print(\"Button was pressed\") app = App() button = PushButton(app, command=do_nothing) app.display() Create a picture PushButton with an image like this: from guizero import App, PushButton def do_nothing(): print(\"A picture button was pressed\") app = App() button = PushButton(app, image=\"button.gif\", command=do_nothing) app.display() Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use for PushButton . By default GIF and PNG are supported, except macOS which only supports GIF.","title":"How do I make one?"},{"location":"pushbutton/#starting-parameters","text":"When you create a PushButton object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: button = PushButton(app) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs command function name None - The name of a function to call when the button is pressed. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display. If both an image and text are specified, the image will override the text. padx int 10 - How much horizontal padding to add between the text/icon and the edge of the button. pady int 10 - How much vertical padding to add between the text/icon and the edge of the button. text string \"Button\" - The text to display on the button visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or pixels if its an image button or to \"fill\" height size None No Set the height of the widget in characters or pixels if its an image button or to \"fill\"","title":"Starting parameters"},{"location":"pushbutton/#methods","text":"You can call the following methods on a PushButton object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(image_source) image_source (string) - The file path, tkinter.PhotoImage or PIL.Image you wish to display. padding(padx, pady) padx (int), pady(int) - Sets the amount of x (horizontal) and y (vertical) padding between the text/icon and the edge of the button repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Changes the state of the button to the opposite of its current state - if it is currently enabled, disable it and vice versa. update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the button is pressed .","title":"Methods"},{"location":"pushbutton/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text on the button grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or pixels if its an image button or to \"fill\" master App or Box The container to which this widget belongs text string The text on the button text_color color The colour of the text on the button text_size int The size of the text on the button value int Returns 1 when the button is pressed, 0 if the button is released visible boolean If this widget is visible width size Set the width of the widget in characters or pixels if its an image button or to \"fill\" Refer to a property as .property . For example, if your PushButton object is called button you would write button.value . You can set the property (for example button.bg = \"red\" ) or get the value of the property to use (for example print(button.bg) ).","title":"Properties"},{"location":"recipes/","text":"Recipes These are examples of how you can use guizero to create user interfaces. Don't be restricted to these ideas, check out Using guizero and the widgets . Hello World Create a guizero app and display some text. from guizero import App, Text app = App() text = Text(app, text=\"hello world\") app.display() Get some text Get some data from the user using a TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Enter your name\") app.display() Push a button Use a PushButton to display a message when the button is pressed. from guizero import App, TextBox, PushButton, Text def update_text(): label.value = name.value app = App() label = Text(app, text=\"What's your name?\") name = TextBox(app) button = PushButton(app, command=update_text) app.display() Display an image Use a Picture object to display an image. from guizero import App, Picture app = App() pic = Picture(app, image=\"myimage.gif\") app.display() Toggle 2 buttons Have 2 buttons, start and stop with them changing the enabled state of each other. from guizero import App, PushButton def start(): start_button.disable() stop_button.enable() def stop(): start_button.enable() stop_button.disable() app = App() start_button = PushButton(app, command=start, text=\"start\") stop_button = PushButton(app, command=stop, text=\"stop\", enabled=False) app.display() Change your apps appearance Your app doesn't have to use the standard colors and text, let your user pick the background and text color from 2 combo's. from guizero import App, Combo, Text def update_bg(): app.bg = bg_combo.value def update_text(): app.text_color = text_combo.value colors = [\"black\", \"white\", \"red\", \"green\", \"blue\"] app = App() app.bg = \"black\" app.text_color = \"white\" title1 = Text(app, text=\"Background color\") bg_combo = Combo(app, options=colors, selected=app.bg, command=update_bg) title2 = Text(app, text=\"Text color\") text_combo = Combo(app, options=colors, selected=app.text_color, command=update_text) app.display() Scale an image Display an image on the screen with 2 sliders, 1 for height and 1 for width. from guizero import App, Slider, Picture def resize(): picture.width = width.value picture.height = height.value app = App(layout=\"grid\") picture = Picture(app, image=\"image.gif\", grid=[0,1]) width = Slider(app, command=resize, grid=[0,0], start=1, end=picture.width) width.width = picture.width width.value = picture.width height = Slider(app, command=resize, horizontal=False, grid=[1,1], start=1, end=picture.height) height.height = picture.height height.value = picture.height app.display()","title":"Recipes"},{"location":"recipes/#recipes","text":"These are examples of how you can use guizero to create user interfaces. Don't be restricted to these ideas, check out Using guizero and the widgets .","title":"Recipes"},{"location":"recipes/#hello-world","text":"Create a guizero app and display some text. from guizero import App, Text app = App() text = Text(app, text=\"hello world\") app.display()","title":"Hello World"},{"location":"recipes/#get-some-text","text":"Get some data from the user using a TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Enter your name\") app.display()","title":"Get some text"},{"location":"recipes/#push-a-button","text":"Use a PushButton to display a message when the button is pressed. from guizero import App, TextBox, PushButton, Text def update_text(): label.value = name.value app = App() label = Text(app, text=\"What's your name?\") name = TextBox(app) button = PushButton(app, command=update_text) app.display()","title":"Push a button"},{"location":"recipes/#display-an-image","text":"Use a Picture object to display an image. from guizero import App, Picture app = App() pic = Picture(app, image=\"myimage.gif\") app.display()","title":"Display an image"},{"location":"recipes/#toggle-2-buttons","text":"Have 2 buttons, start and stop with them changing the enabled state of each other. from guizero import App, PushButton def start(): start_button.disable() stop_button.enable() def stop(): start_button.enable() stop_button.disable() app = App() start_button = PushButton(app, command=start, text=\"start\") stop_button = PushButton(app, command=stop, text=\"stop\", enabled=False) app.display()","title":"Toggle 2 buttons"},{"location":"recipes/#change-your-apps-appearance","text":"Your app doesn't have to use the standard colors and text, let your user pick the background and text color from 2 combo's. from guizero import App, Combo, Text def update_bg(): app.bg = bg_combo.value def update_text(): app.text_color = text_combo.value colors = [\"black\", \"white\", \"red\", \"green\", \"blue\"] app = App() app.bg = \"black\" app.text_color = \"white\" title1 = Text(app, text=\"Background color\") bg_combo = Combo(app, options=colors, selected=app.bg, command=update_bg) title2 = Text(app, text=\"Text color\") text_combo = Combo(app, options=colors, selected=app.text_color, command=update_text) app.display()","title":"Change your apps appearance"},{"location":"recipes/#scale-an-image","text":"Display an image on the screen with 2 sliders, 1 for height and 1 for width. from guizero import App, Slider, Picture def resize(): picture.width = width.value picture.height = height.value app = App(layout=\"grid\") picture = Picture(app, image=\"image.gif\", grid=[0,1]) width = Slider(app, command=resize, grid=[0,0], start=1, end=picture.width) width.width = picture.width width.value = picture.width height = Slider(app, command=resize, horizontal=False, grid=[1,1], start=1, end=picture.height) height.height = picture.height height.value = picture.height app.display()","title":"Scale an image"},{"location":"size/","text":"Sizes You can set the width and height of widgets in guizero. Widgets are sized by either pixels or characters depending on the widget and what it contains. Some widgets size can also be set to \"fill\" where it will use up all of the available space. from guizero import App, PushButton, Slider, ListBox app = App() # A PushButton's size is noted in characters button = PushButton(app, width=30, height=5) # A Slider's size is noted in pixels slider = Slider(app, width=300, height=30) # Some widgets such as ListBox can also be told to fill all the available space listbox = ListBox(app, width=\"fill\", height=\"fill\") app.display() Widget Characters or Pixels Fill Notes Box Pixels Yes If a Box is sized in Pixels, both width and height must be specified. ButtonGroup Characters Yes The height of a ButtonGroup must divide by the number of buttons in it CheckBox Characters Yes Combo Characters Yes ListBox Pixels Yes Picture Pixels No See Images for more information PushButton Characters Yes PushButton with image Pixels No PushButton's which have images are sized in pixels Slider Pixels Yes Text Characters Yes TextBox Characters Yes Only a TextBox's width can be set Waffle Pixels No","title":"Sizes"},{"location":"size/#sizes","text":"You can set the width and height of widgets in guizero. Widgets are sized by either pixels or characters depending on the widget and what it contains. Some widgets size can also be set to \"fill\" where it will use up all of the available space. from guizero import App, PushButton, Slider, ListBox app = App() # A PushButton's size is noted in characters button = PushButton(app, width=30, height=5) # A Slider's size is noted in pixels slider = Slider(app, width=300, height=30) # Some widgets such as ListBox can also be told to fill all the available space listbox = ListBox(app, width=\"fill\", height=\"fill\") app.display() Widget Characters or Pixels Fill Notes Box Pixels Yes If a Box is sized in Pixels, both width and height must be specified. ButtonGroup Characters Yes The height of a ButtonGroup must divide by the number of buttons in it CheckBox Characters Yes Combo Characters Yes ListBox Pixels Yes Picture Pixels No See Images for more information PushButton Characters Yes PushButton with image Pixels No PushButton's which have images are sized in pixels Slider Pixels Yes Text Characters Yes TextBox Characters Yes Only a TextBox's width can be set Waffle Pixels No","title":"Sizes"},{"location":"slider/","text":"Slider (Contains a tkinter.Scale object) __init__( self, master, start=0, end=100, horizontal=True, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Slider object displays a bar and selector which can be used to specify a value in a range. The above code looks like this on Windows: How do I make one? Create a Slider object like this: from guizero import App, Slider app = App() slider = Slider(app) app.display() Starting paramters When you create a Slider object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: slider = Slider(app, horizontal=False) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the slider value is changed end int 100 - The largest value selectable on the slider grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal Boolean True - Whether you wish to display your slider horizontally or vertically (defaults to horizontal) start int 0 - The smallest value selectable on the slider visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" Methods You can call the following methods on a Slider object. Method Takes Returns Description the function specified in command after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the slider value is changed Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text value string The current value of the slider visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" Examples Calling a function when the slider value changes You can specify a function to call when the slider value changes. Your function MUST have a minimum of one parameter as it will automatically receive a string containing the value of the slider (called slider_value in the example) when it is called. This code has a slider and a text box, and the text box updates automatically to display the current value of the slider. from guizero import App, Slider, TextBox def slider_changed(slider_value): textbox.value = slider_value app = App() slider = Slider(app, command=slider_changed) textbox = TextBox(app) app.display()","title":"Slider"},{"location":"slider/#slider","text":"(Contains a tkinter.Scale object) __init__( self, master, start=0, end=100, horizontal=True, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Slider"},{"location":"slider/#what-is-it","text":"The Slider object displays a bar and selector which can be used to specify a value in a range. The above code looks like this on Windows:","title":"What is it?"},{"location":"slider/#how-do-i-make-one","text":"Create a Slider object like this: from guizero import App, Slider app = App() slider = Slider(app) app.display()","title":"How do I make one?"},{"location":"slider/#starting-paramters","text":"When you create a Slider object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: slider = Slider(app, horizontal=False) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the slider value is changed end int 100 - The largest value selectable on the slider grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal Boolean True - Whether you wish to display your slider horizontally or vertically (defaults to horizontal) start int 0 - The smallest value selectable on the slider visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\"","title":"Starting paramters"},{"location":"slider/#methods","text":"You can call the following methods on a Slider object. Method Takes Returns Description the function specified in command after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the slider value is changed","title":"Methods"},{"location":"slider/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text value string The current value of the slider visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\"","title":"Properties"},{"location":"slider/#examples","text":"Calling a function when the slider value changes You can specify a function to call when the slider value changes. Your function MUST have a minimum of one parameter as it will automatically receive a string containing the value of the slider (called slider_value in the example) when it is called. This code has a slider and a text box, and the text box updates automatically to display the current value of the slider. from guizero import App, Slider, TextBox def slider_changed(slider_value): textbox.value = slider_value app = App() slider = Slider(app, command=slider_changed) textbox = TextBox(app) app.display()","title":"Examples"},{"location":"start/","text":"Getting Started At the start of every guizero program, choose the widgets you need from the guizero library and import them: from guizero import App, PushButton, Slider You only need to import each widget once, and then you can use it in your program as many times as you like. Hello World All guizero projects begin with a main window which is called an App . At the end of every guizero program you must tell the program to display the app you have just created. Let's create an app window with the title \"Hello world\": from guizero import App app = App(title=\"Hello world\") app.display() Save and run the code - you've created your first guizero app! Adding widgets Widgets are the things which appear on the GUI, such as text boxes, buttons, sliders and even plain old pieces of text. All widgets go between the line of code to create the App and the app.display() line. from guizero import App, Text app = App(title=\"Hello world\") message = Text(app, text=\"Welcome to the Hello world app!\") app.display() Let\u2019s look at the Text widget code in a bit more detail: message = Text(app, text=\"Welcome to the Hello world app!\") message = - The Text object has a name, just like any variable Text - an object which creates a piece of text on the screen app \u2013 This tells the Text where it will live. Most of the time your widgets will live directly inside the app. text=\"Welcome to the Hello world app!\" - The text to display And that's it! Now have a look on the documentation pages for the individual widgets to find out more about how to use them.","title":"Getting started"},{"location":"start/#getting-started","text":"At the start of every guizero program, choose the widgets you need from the guizero library and import them: from guizero import App, PushButton, Slider You only need to import each widget once, and then you can use it in your program as many times as you like.","title":"Getting Started"},{"location":"start/#hello-world","text":"All guizero projects begin with a main window which is called an App . At the end of every guizero program you must tell the program to display the app you have just created. Let's create an app window with the title \"Hello world\": from guizero import App app = App(title=\"Hello world\") app.display() Save and run the code - you've created your first guizero app!","title":"Hello World"},{"location":"start/#adding-widgets","text":"Widgets are the things which appear on the GUI, such as text boxes, buttons, sliders and even plain old pieces of text. All widgets go between the line of code to create the App and the app.display() line. from guizero import App, Text app = App(title=\"Hello world\") message = Text(app, text=\"Welcome to the Hello world app!\") app.display() Let\u2019s look at the Text widget code in a bit more detail: message = Text(app, text=\"Welcome to the Hello world app!\") message = - The Text object has a name, just like any variable Text - an object which creates a piece of text on the screen app \u2013 This tells the Text where it will live. Most of the time your widgets will live directly inside the app. text=\"Welcome to the Hello world app!\" - The text to display And that's it! Now have a look on the documentation pages for the individual widgets to find out more about how to use them.","title":"Adding widgets"},{"location":"text/","text":"Text (Contains a tkinter.Label object) __init__( self, master, text=\"\", size=12, color=\"black\", bg=None, font=\"Helvetica\", grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Text object displays non editable text in your app, useful for titles, labels and instructions. How do I make one? Create a Text object like this: from guizero import App, Text app = App() text = Text(app, text=\"Hello World\") app.display() Starting parameters When you create a Text object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: text = Text(app, text=\"hi\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color black - The colour of the text. Accepts some colour strings (e.g. red ) and colours specified in hex format (e.g. #0099ff ) font string \"Helvetica\" - The font face that the text will be displayed in. Availability of fonts depends on which fonts are installed locally. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. size int 12 - The font size of the text text string \"\" - The text you want to display visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on a Text object.. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the object cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the text destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text value string The text visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\"","title":"Text"},{"location":"text/#text","text":"(Contains a tkinter.Label object) __init__( self, master, text=\"\", size=12, color=\"black\", bg=None, font=\"Helvetica\", grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Text"},{"location":"text/#what-is-it","text":"The Text object displays non editable text in your app, useful for titles, labels and instructions.","title":"What is it?"},{"location":"text/#how-do-i-make-one","text":"Create a Text object like this: from guizero import App, Text app = App() text = Text(app, text=\"Hello World\") app.display()","title":"How do I make one?"},{"location":"text/#starting-parameters","text":"When you create a Text object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: text = Text(app, text=\"hi\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color black - The colour of the text. Accepts some colour strings (e.g. red ) and colours specified in hex format (e.g. #0099ff ) font string \"Helvetica\" - The font face that the text will be displayed in. Availability of fonts depends on which fonts are installed locally. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. size int 12 - The font size of the text text string \"\" - The text you want to display visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"text/#methods","text":"You can call the following methods on a Text object.. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the object cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the text destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden","title":"Methods"},{"location":"text/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text value string The text visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\"","title":"Properties"},{"location":"textbox/","text":"TextBox (Contains a tkinter.Entry object) __init__( self, master, text=\"\", width=10, height=1, grid=None, align=None, visible=True, enabled=None, multiline=False, scrollbar=False, command=None, hide_text=False) What is it The TextBox object displays a text box which the user can type in. How do I make one? Create a TextBox object like this: from guizero import App, TextBox app = App() input_box = TextBox(app) app.display() Starting parameters When you create a TextBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: textbox = TextBox(app, text=\"Please enter some text\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. text string \"\" - Any text you wish to be pre-filled in the text box width int 10 - Set the width of the widget in characters or to \"fill\" height int 1 - Set the height of the widget in characters or to \"fill\" , only effective if multiline is True visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiline boolean False No Create a multi-line text box. scrollbar boolean False No Add a vertical scrollbar to a multi-line text box command function name None - The name of a function to call when the text is changed. This function MUST take either zero or one argument, if the function takes one argument the key which was added to the textbox will be returned. hide_text boolean False - When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character. Methods You can call the following methods on your TextBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the text box cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the textbox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the text is changed. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" , only effective if multiline is True hide_text boolean / char When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character. master App or Box The container to which this widget belongs value string The text in the TextBox visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text Examples Creating a TextBox with default text You can set the default text in a TextBox when it is created using the text parameter: from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type here\") app.display() Creating a password TextBox with hidden text You can hide the text in a TextBox using the hide_text parameter: from guizero import App, TextBox app = App() password_box = TextBox(app, hide_text=True) app.display() Creating a multi-line TextBox You can create a text box which is capable of capturing multiple lines of text by setting the multiline parameter to True and giving the textbox a height : from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True) app.display() Multi-line text boxes can also be given a scrollbar by setting the scrollbar parameter to True : input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True, scrollbar=True)","title":"TextBox"},{"location":"textbox/#textbox","text":"(Contains a tkinter.Entry object) __init__( self, master, text=\"\", width=10, height=1, grid=None, align=None, visible=True, enabled=None, multiline=False, scrollbar=False, command=None, hide_text=False)","title":"TextBox"},{"location":"textbox/#what-is-it","text":"The TextBox object displays a text box which the user can type in.","title":"What is it"},{"location":"textbox/#how-do-i-make-one","text":"Create a TextBox object like this: from guizero import App, TextBox app = App() input_box = TextBox(app) app.display()","title":"How do I make one?"},{"location":"textbox/#starting-parameters","text":"When you create a TextBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: textbox = TextBox(app, text=\"Please enter some text\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. text string \"\" - Any text you wish to be pre-filled in the text box width int 10 - Set the width of the widget in characters or to \"fill\" height int 1 - Set the height of the widget in characters or to \"fill\" , only effective if multiline is True visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiline boolean False No Create a multi-line text box. scrollbar boolean False No Add a vertical scrollbar to a multi-line text box command function name None - The name of a function to call when the text is changed. This function MUST take either zero or one argument, if the function takes one argument the key which was added to the textbox will be returned. hide_text boolean False - When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character.","title":"Starting parameters"},{"location":"textbox/#methods","text":"You can call the following methods on your TextBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the text box cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the textbox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the text is changed.","title":"Methods"},{"location":"textbox/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" , only effective if multiline is True hide_text boolean / char When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character. master App or Box The container to which this widget belongs value string The text in the TextBox visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text","title":"Properties"},{"location":"textbox/#examples","text":"Creating a TextBox with default text You can set the default text in a TextBox when it is created using the text parameter: from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type here\") app.display() Creating a password TextBox with hidden text You can hide the text in a TextBox using the hide_text parameter: from guizero import App, TextBox app = App() password_box = TextBox(app, hide_text=True) app.display() Creating a multi-line TextBox You can create a text box which is capable of capturing multiple lines of text by setting the multiline parameter to True and giving the textbox a height : from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True) app.display() Multi-line text boxes can also be given a scrollbar by setting the scrollbar parameter to True : input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True, scrollbar=True)","title":"Examples"},{"location":"usingtk/","text":"Using tkinter If you are an advanced user, you can still make use of tkinter when using guizero. You can combine the use of guizero and tkinter seamlessly in a program, taking advantage of the simplified syntax of guizero whilst still being able to access the full range of functionality in tkinter if you need it. Using tkinter widgets in guizero You can add tk widgets into your guizero app using the add_tk_widget method of App , Window and Box . In this example, we are adding the tkinter widget Spinbox into a guizero App : from guizero import App, Text from tkinter import Spinbox app = App() text = Text(app, text=\"A Spinbox widget\") spinbox = Spinbox(from_=0, to=10) app.add_tk_widget(spinbox) app.display() When adding a tk widget to a Box or a Window you will have to specify its tk property when creating the tk widget. box = Box(app) spinbox = Spinbox(box.tk, from_=0, to=10) box.add_tk_widget(spinbox) Using a tkinter method on a guizero object Each guizero widget itself contains a tk widget - you can find out which by looking on the guizero documentation page for the widget. For example, a guizero TextBox contains a tkinter Entry object. You can access the internal object using the syntax .tk . In this example, we have guizero App and TextBox widgets and are using the tk widgets config method to change the mouse cursor when it is over the TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Laura\") name.tk.config(cursor=\"target\") app.display()","title":"Using tkinter"},{"location":"usingtk/#using-tkinter","text":"If you are an advanced user, you can still make use of tkinter when using guizero. You can combine the use of guizero and tkinter seamlessly in a program, taking advantage of the simplified syntax of guizero whilst still being able to access the full range of functionality in tkinter if you need it.","title":"Using tkinter"},{"location":"usingtk/#using-tkinter-widgets-in-guizero","text":"You can add tk widgets into your guizero app using the add_tk_widget method of App , Window and Box . In this example, we are adding the tkinter widget Spinbox into a guizero App : from guizero import App, Text from tkinter import Spinbox app = App() text = Text(app, text=\"A Spinbox widget\") spinbox = Spinbox(from_=0, to=10) app.add_tk_widget(spinbox) app.display() When adding a tk widget to a Box or a Window you will have to specify its tk property when creating the tk widget. box = Box(app) spinbox = Spinbox(box.tk, from_=0, to=10) box.add_tk_widget(spinbox)","title":"Using tkinter widgets in guizero"},{"location":"usingtk/#using-a-tkinter-method-on-a-guizero-object","text":"Each guizero widget itself contains a tk widget - you can find out which by looking on the guizero documentation page for the widget. For example, a guizero TextBox contains a tkinter Entry object. You can access the internal object using the syntax .tk . In this example, we have guizero App and TextBox widgets and are using the tk widgets config method to change the mouse cursor when it is over the TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Laura\") name.tk.config(cursor=\"target\") app.display()","title":"Using a tkinter method on a guizero object"},{"location":"waffle/","text":"Waffle (Contains a tkinter.Frame object) __init__( self, master, height=3, width=3, dim=20, pad=5, color=\"white\", dotty=False, grid=None, align=None, command=None, remember=True, visible=True, enabled=None, bg=None) What is it The Waffle object display an n*n grid of squares with custom dimensions and padding. How do I make one? Create a Waffle object like this: from guizero import App, Waffle app = App() waffle = Waffle(app) app.display() Starting parameters When you create a Waffle object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: waffle = Waffle(app, height=25) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color \"white\" - The default colour of pixels on the waffle command function name None - The name of a function to call when the waffle is clicked. This function MUST take either zero or two arguments, if the function takes two arguments the x and y co-ordinates of the pixel which was clicked will be given. dim int 20 - How large one of the pixels on the waffle is dotty boolean False - Whether the pixels display as dots/circles (True) or squares (False) grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. height int 3 - Set the height in waffle pixels pad int 5 - How much space is between the pixels on the waffle width int 3 - Set the width in waffle pixels visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master bg color None No The background colour of the waffle. Takes a color value. Methods You can call the following methods on your Waffle object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) get_all() - List Returns the pixel colours in the grid as a 2D list. get_pixel(x, y) x (int), y (int) string Returns the colour of the pixel at the specified coordinates. 0,0 is the top left of the grid. hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. pixel(x, y) (int), y (int) WafflePixel Returns the pixel at the specified coordinates. 0,0 is the top left of the grid. Waffle.pixel(x,y) is the equivalent of Waffle[x,y] repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. set_all(color) color ( color ) - Sets all pixels to the specified colour. set_pixel(x, y, color) x (int), y (int), color ( color ) - Sets the pixel at the specified coordinates to the specified colour. 0,0 is the top left of the grid. show() - - Displays the widget update_command(command) command (function name) - Updates the function to call when the Waffle is clicked Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget color color The default colour of pixels on the waffle dotty bool If True the waffle will display circles enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height in waffle pixels master App or Box The container to which this widget belongs pad int The size of the padding between pixels pixel_size int The size of the one pixel width size Set the width in waffle pixels visible boolean If this widget is visible Example Set a pixel colour A Waffle can remember the colour of each pixel within it. from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle[2,1].color = \"red\" # Your waffle will remember what colour each pixel is print(my_waffle[2,1].color) # Even the ones auto-set at the start (which are white by default) print(my_waffle[1,1].color) app.display() WafflePixel A WafflePixel object is returned by Waffle.pixel(x,y) and Waffle[x,y] . from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle.pixel(x,y).color = \"red\" my_waffle[x,y].dotty = True app.display() Properties You can set and get the following properties: Method Data type Description x int Returns the x position of the pixel on the widget x int Returns the y position of the pixel on the widget canvas_x int Returns the x position of the pixel on the canvas canvas_y int Returns the y position of the pixel on the canvas color color Sets or returns the color of the pixel dotty bool Set to True to make the pixel a circle size int Returns the size of the pixel in display pixels","title":"Waffle"},{"location":"waffle/#waffle","text":"(Contains a tkinter.Frame object) __init__( self, master, height=3, width=3, dim=20, pad=5, color=\"white\", dotty=False, grid=None, align=None, command=None, remember=True, visible=True, enabled=None, bg=None)","title":"Waffle"},{"location":"waffle/#what-is-it","text":"The Waffle object display an n*n grid of squares with custom dimensions and padding.","title":"What is it"},{"location":"waffle/#how-do-i-make-one","text":"Create a Waffle object like this: from guizero import App, Waffle app = App() waffle = Waffle(app) app.display()","title":"How do I make one?"},{"location":"waffle/#starting-parameters","text":"When you create a Waffle object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: waffle = Waffle(app, height=25) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color \"white\" - The default colour of pixels on the waffle command function name None - The name of a function to call when the waffle is clicked. This function MUST take either zero or two arguments, if the function takes two arguments the x and y co-ordinates of the pixel which was clicked will be given. dim int 20 - How large one of the pixels on the waffle is dotty boolean False - Whether the pixels display as dots/circles (True) or squares (False) grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. height int 3 - Set the height in waffle pixels pad int 5 - How much space is between the pixels on the waffle width int 3 - Set the width in waffle pixels visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master bg color None No The background colour of the waffle. Takes a color value.","title":"Starting parameters"},{"location":"waffle/#methods","text":"You can call the following methods on your Waffle object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) get_all() - List Returns the pixel colours in the grid as a 2D list. get_pixel(x, y) x (int), y (int) string Returns the colour of the pixel at the specified coordinates. 0,0 is the top left of the grid. hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. pixel(x, y) (int), y (int) WafflePixel Returns the pixel at the specified coordinates. 0,0 is the top left of the grid. Waffle.pixel(x,y) is the equivalent of Waffle[x,y] repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. set_all(color) color ( color ) - Sets all pixels to the specified colour. set_pixel(x, y, color) x (int), y (int), color ( color ) - Sets the pixel at the specified coordinates to the specified colour. 0,0 is the top left of the grid. show() - - Displays the widget update_command(command) command (function name) - Updates the function to call when the Waffle is clicked","title":"Methods"},{"location":"waffle/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget color color The default colour of pixels on the waffle dotty bool If True the waffle will display circles enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height in waffle pixels master App or Box The container to which this widget belongs pad int The size of the padding between pixels pixel_size int The size of the one pixel width size Set the width in waffle pixels visible boolean If this widget is visible","title":"Properties"},{"location":"waffle/#example","text":"Set a pixel colour A Waffle can remember the colour of each pixel within it. from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle[2,1].color = \"red\" # Your waffle will remember what colour each pixel is print(my_waffle[2,1].color) # Even the ones auto-set at the start (which are white by default) print(my_waffle[1,1].color) app.display()","title":"Example"},{"location":"waffle/#wafflepixel","text":"A WafflePixel object is returned by Waffle.pixel(x,y) and Waffle[x,y] . from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle.pixel(x,y).color = \"red\" my_waffle[x,y].dotty = True app.display()","title":"WafflePixel"},{"location":"waffle/#properties_1","text":"You can set and get the following properties: Method Data type Description x int Returns the x position of the pixel on the widget x int Returns the y position of the pixel on the widget canvas_x int Returns the x position of the pixel on the canvas canvas_y int Returns the y position of the pixel on the canvas color color Sets or returns the color of the pixel dotty bool Set to True to make the pixel a circle size int Returns the size of the pixel in display pixels","title":"Properties"},{"location":"widgetoverview/","text":"Overview Widgets are how you create your GUI. They are the things which appear on the GUI, everything from the app itself to text boxes, buttons and pictures. Note: This is an overview of the widgets in guizero. Be sure to view the specific documentation for each widget for more information. Widgets App The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets. app = App() app.display() Box The Box object is an invisible container which can contain other widgets. box = Box(app) box = Box(app, border=True) ButtonGroup The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option. choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"]) CheckBox The CheckBox object displays a check box to allow an option to be ticked or un-ticked. checkbox = CheckBox(app, text=\"salad ?\") Combo The Combo object displays a drop down box allowing a single option to be selected from a list of options. combo = Combo(app, options=[\"cheese\", \"ham\", \"salad\"]) Drawing The Drawing object allows shapes, images and text to be created. drawing = Drawing(app) ListBox The ListBox object displays a list of items from which either single or multiple items can be selected. listbox = ListBox(app, items=[\"cheese\", \"ham\", \"salad\"]) Picture The Picture object displays an image. picture = Picture(app, image=\"guizero.png\") PushButton The PushButton object displays a button with text or an image, which calls a function when pressed. def do_nothing(): print(\"button pressed\") button = PushButton(app, command=do_nothing) Slider The Slider object displays a bar and selector which can be used to specify a value in a range. slider = Slider(app) Text The Text object displays non editable text in your app, useful for titles, labels and instructions. text = Text(app, text=\"Hello World\") TextBox The TextBox object displays a text box which the user can type in. textbox = TextBox(app) Waffle The Waffle object display an n*n grid of squares with custom dimensions and padding. waffle = Waffle(app) Window The Window object create a new window in guizero. window = Window(app) Properties All widgets are customisable through their properties. These properties are typical for most widgets. Check the widgets document for more information. Property Data type Description align string The alignment of this widget within its container bg string, List The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget if in a \"grid\". height int, string The height of the widget. master App, Window, Box The container to which this widget belongs value int, string, bool The widgets current \"value\", e.g. the text in a TextBox visible boolean If this widget is visible width size The width of the widget. text_size int The size of the text text_color color The colour of the text Methods Widgets can be interacted with through their methods. The methods supported are dependent on the widget, so check the documentation. These methods are typical across most widgets. Method Description after(time, command, args=None) Schedules a single call to command after time milliseconds cancel(command) Cancels a scheduled call to command destroy() Destroys the widget disable() Disables the widget so that it cannot be interacted with enable() Enables the widget focus() Gives focus to the widget hide() Hides the widget from view repeat(time, command, args=None) Schedules a call to command every time milliseconds resize(width, height) Sets the width and height of the widget show() Displays the widget if it was previously hidden update_command(command, args =None) Updates the function to call when the widget is used","title":"Overview"},{"location":"widgetoverview/#overview","text":"Widgets are how you create your GUI. They are the things which appear on the GUI, everything from the app itself to text boxes, buttons and pictures. Note: This is an overview of the widgets in guizero. Be sure to view the specific documentation for each widget for more information.","title":"Overview"},{"location":"widgetoverview/#widgets","text":"","title":"Widgets"},{"location":"widgetoverview/#app","text":"The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets. app = App() app.display()","title":"App"},{"location":"widgetoverview/#box","text":"The Box object is an invisible container which can contain other widgets. box = Box(app) box = Box(app, border=True)","title":"Box"},{"location":"widgetoverview/#buttongroup","text":"The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option. choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"])","title":"ButtonGroup"},{"location":"widgetoverview/#checkbox","text":"The CheckBox object displays a check box to allow an option to be ticked or un-ticked. checkbox = CheckBox(app, text=\"salad ?\")","title":"CheckBox"},{"location":"widgetoverview/#combo","text":"The Combo object displays a drop down box allowing a single option to be selected from a list of options. combo = Combo(app, options=[\"cheese\", \"ham\", \"salad\"])","title":"Combo"},{"location":"widgetoverview/#drawing","text":"The Drawing object allows shapes, images and text to be created. drawing = Drawing(app)","title":"Drawing"},{"location":"widgetoverview/#listbox","text":"The ListBox object displays a list of items from which either single or multiple items can be selected. listbox = ListBox(app, items=[\"cheese\", \"ham\", \"salad\"])","title":"ListBox"},{"location":"widgetoverview/#picture","text":"The Picture object displays an image. picture = Picture(app, image=\"guizero.png\")","title":"Picture"},{"location":"widgetoverview/#pushbutton","text":"The PushButton object displays a button with text or an image, which calls a function when pressed. def do_nothing(): print(\"button pressed\") button = PushButton(app, command=do_nothing)","title":"PushButton"},{"location":"widgetoverview/#slider","text":"The Slider object displays a bar and selector which can be used to specify a value in a range. slider = Slider(app)","title":"Slider"},{"location":"widgetoverview/#text","text":"The Text object displays non editable text in your app, useful for titles, labels and instructions. text = Text(app, text=\"Hello World\")","title":"Text"},{"location":"widgetoverview/#textbox","text":"The TextBox object displays a text box which the user can type in. textbox = TextBox(app)","title":"TextBox"},{"location":"widgetoverview/#waffle","text":"The Waffle object display an n*n grid of squares with custom dimensions and padding. waffle = Waffle(app)","title":"Waffle"},{"location":"widgetoverview/#window","text":"The Window object create a new window in guizero. window = Window(app)","title":"Window"},{"location":"widgetoverview/#properties","text":"All widgets are customisable through their properties. These properties are typical for most widgets. Check the widgets document for more information. Property Data type Description align string The alignment of this widget within its container bg string, List The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget if in a \"grid\". height int, string The height of the widget. master App, Window, Box The container to which this widget belongs value int, string, bool The widgets current \"value\", e.g. the text in a TextBox visible boolean If this widget is visible width size The width of the widget. text_size int The size of the text text_color color The colour of the text","title":"Properties"},{"location":"widgetoverview/#methods","text":"Widgets can be interacted with through their methods. The methods supported are dependent on the widget, so check the documentation. These methods are typical across most widgets. Method Description after(time, command, args=None) Schedules a single call to command after time milliseconds cancel(command) Cancels a scheduled call to command destroy() Destroys the widget disable() Disables the widget so that it cannot be interacted with enable() Enables the widget focus() Gives focus to the widget hide() Hides the widget from view repeat(time, command, args=None) Schedules a call to command every time milliseconds resize(width, height) Sets the width and height of the widget show() Displays the widget if it was previously hidden update_command(command, args =None) Updates the function to call when the widget is used","title":"Methods"},{"location":"window/","text":"Window (Contains a tkinter.TopLevel object) __init__( self, master, title=\"guizero\", width=500, height=500, layout=\"auto\", bg=None, visible=True) What is it? The Window object create a new window in guizero. How do I make one? Create an Window object like this: from guizero import App, Window app = App() window = Window(app) app.display() Starting parameters When you create a Window object you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets like this: window = Window(app, bg=\"red\", height=200) Parameter Data type Default Compulsory Description master App - Yes The app to which the window belongs bg color None No The background colour of the window. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the window should be visible. Methods You can call the following methods on a Window object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the window so that they cannot be interacted with destroy() - - Destroys the windows enable() - - Enables all the widgets in the window error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the window hide() - - Hides the window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show(wait = False) - - Displays the window if it was previously hidden update() - - Force the window to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window. Properties You can set and get the following properties: Method Data type Description bg color The background colour of the window children list(widgets) A list of widgets in this container enabled boolean True if the window is enabled font string The font that widgets should use full_screen boolean False height int The height of the window layout string The layout being used by the Window ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use visible boolean If the window is visible width int The width of the window when_closed function The function to call when the Window is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your Window object is called window you would write window.title . You can set the property (for example window.title = \"Hello world\" ) or get the value of the property to use (for example print(window.title) ). Examples Creating a Window object Create an Window object by calling the Window() constructor. You should give the object a name so you can refer to it later - in this case we have called it window . It is best to keep the name you give to your Window object quite short, as you will have to use it to tell other widgets where they should be stored. from guizero import App, Window app = App(title=\"My app\", height=300, width=200) window = Window(title = \"2nd Window\", height=300, width=200) app.display() Showing and hiding a Window Window objects can be shown and hidden using the show() and hide() methods: from guizero import App, Window, PushButton def open_window(): window_2.show() app = App(title=\"My app\", height=300, width=200) window = Window(app, title = \"2nd Window\", height=300, width=200) window.hide() open_button(app, text=\"open 2nd window\", command=open_window) app.display() If you want a Window to become the main window and stop all other windows responding until it is closed you can set the optional wait parameter to True when using show : def open_window(): window_2.show(wait = True)","title":"Window"},{"location":"window/#window","text":"(Contains a tkinter.TopLevel object) __init__( self, master, title=\"guizero\", width=500, height=500, layout=\"auto\", bg=None, visible=True)","title":"Window"},{"location":"window/#what-is-it","text":"The Window object create a new window in guizero.","title":"What is it?"},{"location":"window/#how-do-i-make-one","text":"Create an Window object like this: from guizero import App, Window app = App() window = Window(app) app.display()","title":"How do I make one?"},{"location":"window/#starting-parameters","text":"When you create a Window object you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets like this: window = Window(app, bg=\"red\", height=200) Parameter Data type Default Compulsory Description master App - Yes The app to which the window belongs bg color None No The background colour of the window. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the window should be visible.","title":"Starting parameters"},{"location":"window/#methods","text":"You can call the following methods on a Window object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the window so that they cannot be interacted with destroy() - - Destroys the windows enable() - - Enables all the widgets in the window error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the window hide() - - Hides the window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show(wait = False) - - Displays the window if it was previously hidden update() - - Force the window to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window.","title":"Methods"},{"location":"window/#properties","text":"You can set and get the following properties: Method Data type Description bg color The background colour of the window children list(widgets) A list of widgets in this container enabled boolean True if the window is enabled font string The font that widgets should use full_screen boolean False height int The height of the window layout string The layout being used by the Window ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use visible boolean If the window is visible width int The width of the window when_closed function The function to call when the Window is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your Window object is called window you would write window.title . You can set the property (for example window.title = \"Hello world\" ) or get the value of the property to use (for example print(window.title) ).","title":"Properties"},{"location":"window/#examples","text":"Creating a Window object Create an Window object by calling the Window() constructor. You should give the object a name so you can refer to it later - in this case we have called it window . It is best to keep the name you give to your Window object quite short, as you will have to use it to tell other widgets where they should be stored. from guizero import App, Window app = App(title=\"My app\", height=300, width=200) window = Window(title = \"2nd Window\", height=300, width=200) app.display() Showing and hiding a Window Window objects can be shown and hidden using the show() and hide() methods: from guizero import App, Window, PushButton def open_window(): window_2.show() app = App(title=\"My app\", height=300, width=200) window = Window(app, title = \"2nd Window\", height=300, width=200) window.hide() open_button(app, text=\"open 2nd window\", command=open_window) app.display() If you want a Window to become the main window and stop all other windows responding until it is closed you can set the optional wait parameter to True when using show : def open_window(): window_2.show(wait = True)","title":"Examples"}]}
    \ No newline at end of file
    +{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Installation guizero is designed to allow new learners to quickly and easily create GUIs for their programs. If you can download and unzip a file, you can install guizero - no special permissions or administrator rights are required . If you have administrator rights and are connected to the internet, you can use pip to install or upgrade guizero (recommended). Windows users can also use the Windows MSI installer . Easy install Go to the guizero repository on GitHub. Click the green \"Code\" button and then \"Download ZIP\" Open the zip file Open the guizero-master folder, then copy the guizero folder and paste it into your home directory Windows macOS That's it! When you write your guizero code, make sure you save it into your home directory. Install using pip You can use the command prompt and pip to install guizero for: Windows macOS Raspberry Pi Linux pip can also be used to install additional features and upgrade guizero . Windows Open a command prompt by clicking Start > Windows System > Command Prompt , or by typing 'command' into the start menu's search bar. Type this command and press enter: pip3 install guizero If you experience problems, have a look at this guide to Using pip on Windows . macOS Open a terminal window by clicking Applications > Utilities > Terminal , or by typing 'terminal' into the desktop's search bar. Type this command and press enter: pip3 install guizero Raspberry Pi Open a terminal window by clicking Menu > Accessories > Terminal . Type this command and press enter: sudo pip3 install guizero Linux Open a terminal Install tkinter using your distribution's package manager, e.g. sudo apt install python3-tk Install guizero using pip by typing pip3 install guizero or sudo pip3 install guizero if you don't have superuser rights Note: If you are using Debian, you alternatively have the option to install guizero via apt sudo apt-get install python-guizero Install additional features To use the additional image features of guizero such as: JPG image support scaling images animated gifs ... you will need to install guizero with the pip command: Windows / macOS pip3 install guizero[images] Linux / Raspberry Pi sudo pip3 install guizero[images] The additional image features are not available to install using the easy install method. Upgrading guizero If you installed guizero using pip, you can upgrade guizero using a pip command: Windows / macOS pip3 install guizero --upgrade Linux / Raspberry Pi sudo pip3 install guizero --upgrade If you installed guizero using the easy install method, to upgrade you should follow the same easy installation steps to download the latest version of guizero, then delete the old guizero folder and replace it with the newest version. Windows MSI installer If you are using Windows you can install guizero by downloading and running a Windows MSI installer application. Download either the 64-bit guizero installer or the 32-bit guizero installer depending on which version of Python you are using. Note: If you are not sure what version of python you are running, run the following program in Python, which will output either 32 or 64 : import struct print(struct.calcsize(\"P\") * 8) Run the guizero installer and select whether guizero should be installed for all users or just for me and click Next . Select which version(s) of Python you want to install guizero for and click Next . Note: For most people, there will be only one version of Python and you can safely choose the default option. You may be asked \"Do you wish to allow this application from an unknown publisher to make changes to your device?\" - click Yes . Wait while guizero is installed. Click Finish when the installation is complete.","title":"Installation"},{"location":"#installation","text":"guizero is designed to allow new learners to quickly and easily create GUIs for their programs. If you can download and unzip a file, you can install guizero - no special permissions or administrator rights are required . If you have administrator rights and are connected to the internet, you can use pip to install or upgrade guizero (recommended). Windows users can also use the Windows MSI installer .","title":"Installation"},{"location":"#easy-install","text":"Go to the guizero repository on GitHub. Click the green \"Code\" button and then \"Download ZIP\" Open the zip file Open the guizero-master folder, then copy the guizero folder and paste it into your home directory Windows macOS That's it! When you write your guizero code, make sure you save it into your home directory.","title":"Easy install"},{"location":"#install-using-pip","text":"You can use the command prompt and pip to install guizero for: Windows macOS Raspberry Pi Linux pip can also be used to install additional features and upgrade guizero .","title":"Install using pip"},{"location":"#windows","text":"Open a command prompt by clicking Start > Windows System > Command Prompt , or by typing 'command' into the start menu's search bar. Type this command and press enter: pip3 install guizero If you experience problems, have a look at this guide to Using pip on Windows .","title":"Windows"},{"location":"#macos","text":"Open a terminal window by clicking Applications > Utilities > Terminal , or by typing 'terminal' into the desktop's search bar. Type this command and press enter: pip3 install guizero","title":"macOS"},{"location":"#raspberry-pi","text":"Open a terminal window by clicking Menu > Accessories > Terminal . Type this command and press enter: sudo pip3 install guizero","title":"Raspberry Pi"},{"location":"#linux","text":"Open a terminal Install tkinter using your distribution's package manager, e.g. sudo apt install python3-tk Install guizero using pip by typing pip3 install guizero or sudo pip3 install guizero if you don't have superuser rights Note: If you are using Debian, you alternatively have the option to install guizero via apt sudo apt-get install python-guizero","title":"Linux"},{"location":"#install-additional-features","text":"To use the additional image features of guizero such as: JPG image support scaling images animated gifs ... you will need to install guizero with the pip command: Windows / macOS pip3 install guizero[images] Linux / Raspberry Pi sudo pip3 install guizero[images] The additional image features are not available to install using the easy install method.","title":"Install additional features"},{"location":"#upgrading-guizero","text":"If you installed guizero using pip, you can upgrade guizero using a pip command: Windows / macOS pip3 install guizero --upgrade Linux / Raspberry Pi sudo pip3 install guizero --upgrade If you installed guizero using the easy install method, to upgrade you should follow the same easy installation steps to download the latest version of guizero, then delete the old guizero folder and replace it with the newest version.","title":"Upgrading guizero"},{"location":"#windows-msi-installer","text":"If you are using Windows you can install guizero by downloading and running a Windows MSI installer application. Download either the 64-bit guizero installer or the 32-bit guizero installer depending on which version of Python you are using. Note: If you are not sure what version of python you are running, run the following program in Python, which will output either 32 or 64 : import struct print(struct.calcsize(\"P\") * 8) Run the guizero installer and select whether guizero should be installed for all users or just for me and click Next . Select which version(s) of Python you want to install guizero for and click Next . Note: For most people, there will be only one version of Python and you can safely choose the default option. You may be asked \"Do you wish to allow this application from an unknown publisher to make changes to your device?\" - click Yes . Wait while guizero is installed. Click Finish when the installation is complete.","title":"Windows MSI installer"},{"location":"about/","text":"About What is guizero? guizero is a Python 3 library for creating simple GUIs. It is designed to allow new learners to quickly and easily create GUIs for their programs. from guizero import App, Text, PushButton app = App(title=\"guizero\") intro = Text(app, text=\"Have a go with guizero and see what you can create.\") ok = PushButton(app, text=\"Ok\") app.display() Aims The aim of guizero is to make the process of creating simple GUIs quick, accessible and understandable for new learners. Works with standard Python Tkinter GUI library (and no need to install other libraries) Abstracts away details new learners find difficult to understand (such as Tkinter StringVar() objects) Accessible widget naming system to help new learners to build up a mental model Flexible enough to be used for projects up to A-Level standard, yet accessible to primary school children Comprehensive and accessible documentation with examples Generates helpful additional error messages Version guizero is currently version 1.1.1","title":"About"},{"location":"about/#about","text":"","title":"About"},{"location":"about/#what-is-guizero","text":"guizero is a Python 3 library for creating simple GUIs. It is designed to allow new learners to quickly and easily create GUIs for their programs. from guizero import App, Text, PushButton app = App(title=\"guizero\") intro = Text(app, text=\"Have a go with guizero and see what you can create.\") ok = PushButton(app, text=\"Ok\") app.display()","title":"What is guizero?"},{"location":"about/#aims","text":"The aim of guizero is to make the process of creating simple GUIs quick, accessible and understandable for new learners. Works with standard Python Tkinter GUI library (and no need to install other libraries) Abstracts away details new learners find difficult to understand (such as Tkinter StringVar() objects) Accessible widget naming system to help new learners to build up a mental model Flexible enough to be used for projects up to A-Level standard, yet accessible to primary school children Comprehensive and accessible documentation with examples Generates helpful additional error messages","title":"Aims"},{"location":"about/#version","text":"guizero is currently version 1.1.1","title":"Version"},{"location":"alerts/","text":"Pop-ups Pop-up windows which can be used to interrupt the user by asking question or providing information. Using pop-ups Pop-ups can be called from an App or Window object, for example: app.info(\"info\", \"this is a guizero app\") Pop-ups can also be imported individually at the start of your program, for example: from guizero import info info(\"info\", \"this is a guizero app\") Purpose These functions pop up a box on the screen that displays a message or asks a question. The functions available are: warn(title, text) - popup box with a warning icon info(title, text) - popup box with an information icon error(title, text) - popup box with an error icon yesno(title, text) - popup box with yes and no options. Pressing Yes returns True and pressing No returns False . question(title, text, initial_value=None) - popup box with a question box which can accept a text response. Pressing Ok returns value entered into the box is returned and pressing Cancel returns None . select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \"*.*\"]], save=False) - popup file dialog box which asks the user to select a file. By default, an Open button is displayed, setting save to True will change the button to Save as . The path of the selected file is returned by the function. select_folder(title=\"Select folder\", folder=\".\") - popup box which asks the user to select a folder. The path of the selected folder is returned by the function. All pop up boxes use the native display, so they will look different depending on your operating system. Examples Warning box This will pop up a warning box with the title \"Uh oh!\" and the message \"You are almost out of biscuits!\" . from guizero import App app = App(title=\"Biscuit monitor\") app.warn(\"Uh oh!\", \"You are almost out of biscuits!\") app.display() On Windows, the box looks like this: The info and error boxes work in exactly the same way but will display different icons. Yes/No box When this function is called it returns a boolean value. If Yes was pressed, return True If No was pressed, return False You can store this value in a variable and test it: from guizero import App app = App(title=\"Snowman\") build_a_snowman = app.yesno(\"A question...\", \"Do you want to build a snowman?\") if build_a_snowman == True: app.info(\"Snowman\", \"It doesn't have to be a snowman\") else: app.error(\"Snowman\", \"Okay bye...\") app.display() This code will first display the yes/no box If Yes is pressed, an information box will be displayed: If No is pressed, an error box will be displayed Example: Using an alert as a callback You can also use these functions in a callback (when you have to provide a function for another widget to call). Here is an example with a PushButton which pops up an info box when it is pressed. from guizero import App, PushButton, info app = App() button = PushButton(app, command=app.info, args=[\"Info\", \"You pressed the button\"]) app.display() The arguments provided to the PushButton are: Where the button should be created (within the app ) The name of the function to call when pressed ( info ) A list of the arguments to the function you are calling (values for the title and message arguments for the info function) Example: Do you really want to close? You can use a yesno box to check whether someone really wants to exit your app. If they click yes, the app is closed, if not, nothing happens and they can continue with what they were doing. from guizero import App, Text # Ask the user if they really want to close the window def do_this_when_closed(): if app.yesno(\"Close\", \"Do you want to quit?\"): app.destroy() app = App() title = Text(app, text=\"blank app\") # When the user tries to close the window, run the function do_this_when_closed() app.when_closed = do_this_when_closed app.display() Example: Asking a question You can use a question pop-up to get information from the user. In this example the user is asked to enter their name when a button is pressed. from guizero import App, PushButton, Text def button_pressed(): name = app.question(\"Hello\", \"What's your name?\") # If cancel is pressed, None is returned # so check a name was entered if name is not None: hello.value = \"Hello \" + name app = App() button = PushButton(app, command=button_pressed, text=\"Hello\") hello = Text(app) app.display() Example: Get a file name Ask the user to select a file using the select_file pop-up. from guizero import App, PushButton, Text def get_file(): file_name.value = app.select_file() app = App() PushButton(app, command=get_file, text=\"Get file\") file_name = Text(app) app.display() You can change the file type filter by providing a list of type descriptions and extensions as the filetypes parameter e.g. file_name.value = app.select_file(filetypes=[[\"All files\", \"*.*\"], [\"Text documents\", \"*.txt\"]]) The default is to show an Open button, this can be changed to a Save button by setting the save parameter to True e.g. file_name.value = app.select_file(save=True) Example: Get a folder name Select a folder using the select_folder pop-up. from guizero import App, PushButton, Text def get_folder(): path.value = app.select_folder() app = App() PushButton(app, command=get_folder, text=\"Get path\") path = Text(app) app.display() You can set the initial folder by passing a path to the folder parameter file_name.value = app.select_file(folder=\"c:\\users\\lawsie\")","title":"Pop-ups"},{"location":"alerts/#pop-ups","text":"Pop-up windows which can be used to interrupt the user by asking question or providing information.","title":"Pop-ups"},{"location":"alerts/#using-pop-ups","text":"Pop-ups can be called from an App or Window object, for example: app.info(\"info\", \"this is a guizero app\") Pop-ups can also be imported individually at the start of your program, for example: from guizero import info info(\"info\", \"this is a guizero app\")","title":"Using pop-ups"},{"location":"alerts/#purpose","text":"These functions pop up a box on the screen that displays a message or asks a question. The functions available are: warn(title, text) - popup box with a warning icon info(title, text) - popup box with an information icon error(title, text) - popup box with an error icon yesno(title, text) - popup box with yes and no options. Pressing Yes returns True and pressing No returns False . question(title, text, initial_value=None) - popup box with a question box which can accept a text response. Pressing Ok returns value entered into the box is returned and pressing Cancel returns None . select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \"*.*\"]], save=False) - popup file dialog box which asks the user to select a file. By default, an Open button is displayed, setting save to True will change the button to Save as . The path of the selected file is returned by the function. select_folder(title=\"Select folder\", folder=\".\") - popup box which asks the user to select a folder. The path of the selected folder is returned by the function. All pop up boxes use the native display, so they will look different depending on your operating system.","title":"Purpose"},{"location":"alerts/#examples","text":"Warning box This will pop up a warning box with the title \"Uh oh!\" and the message \"You are almost out of biscuits!\" . from guizero import App app = App(title=\"Biscuit monitor\") app.warn(\"Uh oh!\", \"You are almost out of biscuits!\") app.display() On Windows, the box looks like this: The info and error boxes work in exactly the same way but will display different icons. Yes/No box When this function is called it returns a boolean value. If Yes was pressed, return True If No was pressed, return False You can store this value in a variable and test it: from guizero import App app = App(title=\"Snowman\") build_a_snowman = app.yesno(\"A question...\", \"Do you want to build a snowman?\") if build_a_snowman == True: app.info(\"Snowman\", \"It doesn't have to be a snowman\") else: app.error(\"Snowman\", \"Okay bye...\") app.display() This code will first display the yes/no box If Yes is pressed, an information box will be displayed: If No is pressed, an error box will be displayed Example: Using an alert as a callback You can also use these functions in a callback (when you have to provide a function for another widget to call). Here is an example with a PushButton which pops up an info box when it is pressed. from guizero import App, PushButton, info app = App() button = PushButton(app, command=app.info, args=[\"Info\", \"You pressed the button\"]) app.display() The arguments provided to the PushButton are: Where the button should be created (within the app ) The name of the function to call when pressed ( info ) A list of the arguments to the function you are calling (values for the title and message arguments for the info function) Example: Do you really want to close? You can use a yesno box to check whether someone really wants to exit your app. If they click yes, the app is closed, if not, nothing happens and they can continue with what they were doing. from guizero import App, Text # Ask the user if they really want to close the window def do_this_when_closed(): if app.yesno(\"Close\", \"Do you want to quit?\"): app.destroy() app = App() title = Text(app, text=\"blank app\") # When the user tries to close the window, run the function do_this_when_closed() app.when_closed = do_this_when_closed app.display() Example: Asking a question You can use a question pop-up to get information from the user. In this example the user is asked to enter their name when a button is pressed. from guizero import App, PushButton, Text def button_pressed(): name = app.question(\"Hello\", \"What's your name?\") # If cancel is pressed, None is returned # so check a name was entered if name is not None: hello.value = \"Hello \" + name app = App() button = PushButton(app, command=button_pressed, text=\"Hello\") hello = Text(app) app.display() Example: Get a file name Ask the user to select a file using the select_file pop-up. from guizero import App, PushButton, Text def get_file(): file_name.value = app.select_file() app = App() PushButton(app, command=get_file, text=\"Get file\") file_name = Text(app) app.display() You can change the file type filter by providing a list of type descriptions and extensions as the filetypes parameter e.g. file_name.value = app.select_file(filetypes=[[\"All files\", \"*.*\"], [\"Text documents\", \"*.txt\"]]) The default is to show an Open button, this can be changed to a Save button by setting the save parameter to True e.g. file_name.value = app.select_file(save=True) Example: Get a folder name Select a folder using the select_folder pop-up. from guizero import App, PushButton, Text def get_folder(): path.value = app.select_folder() app = App() PushButton(app, command=get_folder, text=\"Get path\") path = Text(app) app.display() You can set the initial folder by passing a path to the folder parameter file_name.value = app.select_file(folder=\"c:\\users\\lawsie\")","title":"Examples"},{"location":"app/","text":"App __init__( self, title=\"guizero\", width=500, height=500, layout=\"auto\", bgcolor=None, bg=None, visible=True) What is it? The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets. How do I make one? Create an App object like this: from guizero import App app = App() app.display() Starting parameters When you create an App object you can specify any of the following parameters, all of which are optional. Specify parameters in the brackets like this: app = App(bg=\"red\", height=200) Parameter Data type Default Compulsory Description bg color None No The background colour of the app window and widgets inside it. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the App should be visible. Methods You can call the following methods on an App object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables all the widgets in the app so that they cannot be interacted with display() - - Displays the app on the screen. You MUST call this method at the end of your program to display the app on the screen. enable() - - Enables all the widgets in the app error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the widget hide() - - Hides the app window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show() - - Displays the app window if it was previously hidden update() - - Force the application to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window. Parameters in italics will still work but are deprecated - this means you should stop using them because they may not work in future versions of guizero Properties You can set and get the following properties: Method Data type Description bg color The background colour of the window children List A list of widgets in this container enabled boolean True if the app is enabled height int The height of the window font string The font that widgets should use full_screen boolean False layout string The layout being used by the App ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use tk tkinter.Tk The internal tkinter object, see Using tkinter visible boolean If the app is visible width int The width of the window when_closed function The function to call when the App is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your App object is called app you would write app.title . You can set the property (for example app.title = \"Hello world\" ) or get the value of the property to use (for example print(app.title) ). Examples Creating an App object Create an App object by calling the App() constructor. You should give the object a name so you can refer to it later - in this case we have called it app . It is best to keep the name you give to your App object quite short, as you will have to use it to tell other widgets where they should be stored. At the end of the program you MUST tell the app object to begin the display loop. from guizero import App app = App(title=\"My app\", height=300, width=200) app.display() Changing the title You can change the title of the app object once it has been created like this: from guizero import App app = App(title=\"My app\", height=300, width=200) app.title = \"A different title\" app.display() This will display the app with the updated title:","title":"App"},{"location":"app/#app","text":"__init__( self, title=\"guizero\", width=500, height=500, layout=\"auto\", bgcolor=None, bg=None, visible=True)","title":"App"},{"location":"app/#what-is-it","text":"The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets.","title":"What is it?"},{"location":"app/#how-do-i-make-one","text":"Create an App object like this: from guizero import App app = App() app.display()","title":"How do I make one?"},{"location":"app/#starting-parameters","text":"When you create an App object you can specify any of the following parameters, all of which are optional. Specify parameters in the brackets like this: app = App(bg=\"red\", height=200) Parameter Data type Default Compulsory Description bg color None No The background colour of the app window and widgets inside it. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the App should be visible.","title":"Starting parameters"},{"location":"app/#methods","text":"You can call the following methods on an App object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables all the widgets in the app so that they cannot be interacted with display() - - Displays the app on the screen. You MUST call this method at the end of your program to display the app on the screen. enable() - - Enables all the widgets in the app error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the widget hide() - - Hides the app window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show() - - Displays the app window if it was previously hidden update() - - Force the application to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window. Parameters in italics will still work but are deprecated - this means you should stop using them because they may not work in future versions of guizero","title":"Methods"},{"location":"app/#properties","text":"You can set and get the following properties: Method Data type Description bg color The background colour of the window children List A list of widgets in this container enabled boolean True if the app is enabled height int The height of the window font string The font that widgets should use full_screen boolean False layout string The layout being used by the App ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use tk tkinter.Tk The internal tkinter object, see Using tkinter visible boolean If the app is visible width int The width of the window when_closed function The function to call when the App is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your App object is called app you would write app.title . You can set the property (for example app.title = \"Hello world\" ) or get the value of the property to use (for example print(app.title) ).","title":"Properties"},{"location":"app/#examples","text":"Creating an App object Create an App object by calling the App() constructor. You should give the object a name so you can refer to it later - in this case we have called it app . It is best to keep the name you give to your App object quite short, as you will have to use it to tell other widgets where they should be stored. At the end of the program you MUST tell the app object to begin the display loop. from guizero import App app = App(title=\"My app\", height=300, width=200) app.display() Changing the title You can change the title of the app object once it has been created like this: from guizero import App app = App(title=\"My app\", height=300, width=200) app.title = \"A different title\" app.display() This will display the app with the updated title:","title":"Examples"},{"location":"blocking/","text":"Loops and sleeping You may be used to writing programs which contain loops or make use of the sleep() command, but find when you try to use these with guizero they cause your GUI to freeze. This is because guizero (in common with almost all GUIs) operates an event driven model of programming which may be different to the one you are familiar with. Your first guizero program might look a bit like this: from guizero import App app = App(\"Hello world\") app.display() The line of code app.display() doesn't just display the app - it enters an infinite event loop which is watching and waiting for events to happen on the GUI. Events include things like the user clicking on a button, moving a slider, typing in a text box etc. No code written after this line will ever execute because the event loop is infinite. Example Suppose you want a counter on your GUI to start counting up by 1 every second. You might be tempted to write a program like this: from guizero import App, Text from time import sleep app = App(\"Hello world\") text = Text(app, text=\"1\") while True: text.value = int(text.value) + 1 sleep(1) app.display() If you run this program, you'll see that this does not have the desired effect - your program crashes! This is because you have blocked the updating of your GUI in two ways: The sleep() command - whilst your program is sleeping, the GUI will not update and you will not be able to click on anything. The while loop - once you enter this loop, your GUI will never update ever again and will probably crash. Solution This behaviour is not a bug within guizero or tkinter. You must write GUI based programs in a different way to the one you may be used to. If you want to repeatedly perform an action you would do it like this: Write a function which performs the desired action (in this example counter() ) Set a callback to that function. You can either schedule the same callback to occur repeatedly after a given number of milliseconds (in this example 1000 ), or you can schedule it only once. from guizero import App, Text # Action you would like to perform def counter(): text.value = int(text.value) + 1 app = App(\"Hello world\") text = Text(app, text=\"1\") text.repeat(1000, counter) # Schedule call to counter() every 1000ms app.display()","title":"Loops and sleeping"},{"location":"blocking/#loops-and-sleeping","text":"You may be used to writing programs which contain loops or make use of the sleep() command, but find when you try to use these with guizero they cause your GUI to freeze. This is because guizero (in common with almost all GUIs) operates an event driven model of programming which may be different to the one you are familiar with. Your first guizero program might look a bit like this: from guizero import App app = App(\"Hello world\") app.display() The line of code app.display() doesn't just display the app - it enters an infinite event loop which is watching and waiting for events to happen on the GUI. Events include things like the user clicking on a button, moving a slider, typing in a text box etc. No code written after this line will ever execute because the event loop is infinite.","title":"Loops and sleeping"},{"location":"blocking/#example","text":"Suppose you want a counter on your GUI to start counting up by 1 every second. You might be tempted to write a program like this: from guizero import App, Text from time import sleep app = App(\"Hello world\") text = Text(app, text=\"1\") while True: text.value = int(text.value) + 1 sleep(1) app.display() If you run this program, you'll see that this does not have the desired effect - your program crashes! This is because you have blocked the updating of your GUI in two ways: The sleep() command - whilst your program is sleeping, the GUI will not update and you will not be able to click on anything. The while loop - once you enter this loop, your GUI will never update ever again and will probably crash.","title":"Example"},{"location":"blocking/#solution","text":"This behaviour is not a bug within guizero or tkinter. You must write GUI based programs in a different way to the one you may be used to. If you want to repeatedly perform an action you would do it like this: Write a function which performs the desired action (in this example counter() ) Set a callback to that function. You can either schedule the same callback to occur repeatedly after a given number of milliseconds (in this example 1000 ), or you can schedule it only once. from guizero import App, Text # Action you would like to perform def counter(): text.value = int(text.value) + 1 app = App(\"Hello world\") text = Text(app, text=\"1\") text.repeat(1000, counter) # Schedule call to counter() every 1000ms app.display()","title":"Solution"},{"location":"book/","text":"Book Create Graphical User Interfaces with Python The authors of guizero have written a book containing ten fun guizero projects. The book starts from a very basic GUI and shows you how to create gradually more complex GUI programs including a painting program and a stop-motion animation creator. You can buy the book in print or download it as a free PDF .","title":"Book"},{"location":"book/#book","text":"","title":"Book"},{"location":"book/#create-graphical-user-interfaces-with-python","text":"The authors of guizero have written a book containing ten fun guizero projects. The book starts from a very basic GUI and shows you how to create gradually more complex GUI programs including a painting program and a stop-motion animation creator. You can buy the book in print or download it as a free PDF .","title":"Create Graphical User Interfaces with Python"},{"location":"box/","text":"Box __init__( self, master, layout=\"auto\", grid=None, align=None, visible=True, enabled=None, width=None, height=None, border=None) What is it? The Box object is an invisible container which can contain other widgets. It is the only object other than App and Window which can act as the master for other objects and can have its own layout manager. You can use the Box object to group other objects within your GUI. How do I make one? Create a Box object like this: from guizero import App, Box app = App() box = Box(app) app.display() Starting parameters When you create a Box object you must specify a master, and you can specify any of the optional parameters. Specify parameters in the brackets like this: box = Box(app, layout=\"grid\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. layout string \"auto\" - Whether widgets inside this box pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" border int None No Sets the border thickness. 0 or False is no border. True or value > 1 sets a border. Methods You can call the following methods on a Box object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the box so that they cannot be interacted with destroy() - - Destroys the widget enable() - - Enables all the widgets in the box focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget set_border(thickness, color) thickness (int), color ( color ) - Sets the border thickness and color. Setting thickness to 0 will result in no border. show() - - Displays the widget if it was previously hidden Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container border int The border thickness, setting to 0 or False (the default) there is no border. bg color The background colour of the widget children List A list of widgets in this container enabled boolean True if the box is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid font string The font that widgets should use height size Set the height of the widget in pixels or to \"fill\" layout string The layout being used by the Box ( \"auto\" ) or ( \"grid\" ) master App The App object to which this box belongs text_size int The size of the text widgets should use text_color color The colour of the text widgets should use tk tkinter.Frame The internal tkinter object, see Using tkinter visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" Examples Putting widgets in a Box A Box object is invisible, but it can contain other widgets. In this example, there are two Text objects. One has box as its master, the other has app as its master. from guizero import App, Box, Text app = App(title=\"My app\", height=300, width=400) box = Box(app) text1 = Text(box, text=\"Hello from the box\", size=14, text_color=\"red\", font=\"Arial\") text2 = Text(app, text=\"Hello from the app\", size=14, text_color=\"blue\", font=\"Courier New\") app.display() Grouping objects within a Box It is useful to put objects in a box to group them together. For example here we have given the app a grid layout, then placed some text at [0,0] and the Box object at [1,0]. This means that the text will appear on the left, and the contents of the Box will appear on the right. The Box object itself has a grid layout and contains six buttons which are positioned on a separate grid layout belonging to the box. from guizero import App, Text, Box, PushButton def do_nothing(): return 0 app = App(title=\"My app\", height=300, width=300, layout=\"grid\") text = Text(app, text=\"Some text here\", grid=[0,0]) box = Box(app, layout=\"grid\", grid=[1,0]) button1 = PushButton(box, command=do_nothing, text=\"1\", grid=[0,0]) button2 = PushButton(box, command=do_nothing, text=\"2\", grid=[1,0]) button3 = PushButton(box, command=do_nothing, text=\"3\", grid=[2,0]) button4 = PushButton(box, command=do_nothing, text=\"4\", grid=[0,1]) button5 = PushButton(box, command=do_nothing, text=\"5\", grid=[1,1]) button6 = PushButton(box, command=do_nothing, text=\"6\", grid=[2,1]) app.display()","title":"Box"},{"location":"box/#box","text":"__init__( self, master, layout=\"auto\", grid=None, align=None, visible=True, enabled=None, width=None, height=None, border=None)","title":"Box"},{"location":"box/#what-is-it","text":"The Box object is an invisible container which can contain other widgets. It is the only object other than App and Window which can act as the master for other objects and can have its own layout manager. You can use the Box object to group other objects within your GUI.","title":"What is it?"},{"location":"box/#how-do-i-make-one","text":"Create a Box object like this: from guizero import App, Box app = App() box = Box(app) app.display()","title":"How do I make one?"},{"location":"box/#starting-parameters","text":"When you create a Box object you must specify a master, and you can specify any of the optional parameters. Specify parameters in the brackets like this: box = Box(app, layout=\"grid\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. layout string \"auto\" - Whether widgets inside this box pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" border int None No Sets the border thickness. 0 or False is no border. True or value > 1 sets a border.","title":"Starting parameters"},{"location":"box/#methods","text":"You can call the following methods on a Box object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the box so that they cannot be interacted with destroy() - - Destroys the widget enable() - - Enables all the widgets in the box focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget set_border(thickness, color) thickness (int), color ( color ) - Sets the border thickness and color. Setting thickness to 0 will result in no border. show() - - Displays the widget if it was previously hidden","title":"Methods"},{"location":"box/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container border int The border thickness, setting to 0 or False (the default) there is no border. bg color The background colour of the widget children List A list of widgets in this container enabled boolean True if the box is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid font string The font that widgets should use height size Set the height of the widget in pixels or to \"fill\" layout string The layout being used by the Box ( \"auto\" ) or ( \"grid\" ) master App The App object to which this box belongs text_size int The size of the text widgets should use text_color color The colour of the text widgets should use tk tkinter.Frame The internal tkinter object, see Using tkinter visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\"","title":"Properties"},{"location":"box/#examples","text":"Putting widgets in a Box A Box object is invisible, but it can contain other widgets. In this example, there are two Text objects. One has box as its master, the other has app as its master. from guizero import App, Box, Text app = App(title=\"My app\", height=300, width=400) box = Box(app) text1 = Text(box, text=\"Hello from the box\", size=14, text_color=\"red\", font=\"Arial\") text2 = Text(app, text=\"Hello from the app\", size=14, text_color=\"blue\", font=\"Courier New\") app.display() Grouping objects within a Box It is useful to put objects in a box to group them together. For example here we have given the app a grid layout, then placed some text at [0,0] and the Box object at [1,0]. This means that the text will appear on the left, and the contents of the Box will appear on the right. The Box object itself has a grid layout and contains six buttons which are positioned on a separate grid layout belonging to the box. from guizero import App, Text, Box, PushButton def do_nothing(): return 0 app = App(title=\"My app\", height=300, width=300, layout=\"grid\") text = Text(app, text=\"Some text here\", grid=[0,0]) box = Box(app, layout=\"grid\", grid=[1,0]) button1 = PushButton(box, command=do_nothing, text=\"1\", grid=[0,0]) button2 = PushButton(box, command=do_nothing, text=\"2\", grid=[1,0]) button3 = PushButton(box, command=do_nothing, text=\"3\", grid=[2,0]) button4 = PushButton(box, command=do_nothing, text=\"4\", grid=[0,1]) button5 = PushButton(box, command=do_nothing, text=\"5\", grid=[1,1]) button6 = PushButton(box, command=do_nothing, text=\"6\", grid=[2,1]) app.display()","title":"Examples"},{"location":"buttongroup/","text":"ButtonGroup __init__( self, master, options=[], selected=None, horizontal=False, command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None) What is it? The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option. How do I make one? Create a ButtonGroup object like this: from guizero import App, ButtonGroup app = App() choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=\"cheese\") app.display() Starting parameters When you create a ButtonGroup object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets like this: choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=1) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options list or 2D List - No Either a list or a 2D list of [text, value] pairs. If a 2D list is specified, the first item in the pair will be displayed on the interface, and the second item will be a hidden value associated with this option. selected string - - The option that should be selected, if a value isn't provided the first option will be selected. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the selected option changes. args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid list [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal boolean False - Whether the buttons stack vertically or horizontally. (Defaults to vertical) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on an ButtonGroup object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the ButtonGroup. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget get_group_as_list() - list Returns a list containing all of the text/hidden value pairs from the ButtonGroup (useful for debugging) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), option (string) - Insert a new option in the ButtonGroup at index remove(option) item (string) Boolean Removes the first option from the ButtonGroup. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the selected option changes Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget children List A list of the widgets in this container. [RadioButton, *] enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The hidden value associated with the currently selected option value_text string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Frame The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your ButtonGroup object is called choice you would write choice.value . You can set the property (for example choice.value = \"2\" ) or get the value of the property to use (for example print(choice.value) ). Examples Creating a ButtonGroup with a 2D list If you want to create a ButtonGroup object with your own hidden values you can specify a 2D list of options: from guizero import App, ButtonGroup, Text def update_text(): what_is_selected.value = activities.value app = App() activities = ButtonGroup(app, options=[ [\"Roller Skating\", \"skate\"], [\"White water rafting\", \"WWR\"], [\"Mountain climbing\", \"climb\"] ], selected=\"skate\", command=update_text) what_is_selected = Text(app, text=\"skate\") app.display() Using ButtonGroup tk widgets Advanced users can gain internal access to the internal tkinter widgets used by ButtonGroup . For more information on using tkinter in combination with guizero see Using tkinter . The ButtonGroup widget contains a tkinter.Frame object, which frames multiple guizero RadioButton widgets. Each RadioButton widget contains a tkinter.Radiobutton object. The .children property returns the list of RadioButton widgets in the order they appear in the ButtonGroup : To access the internal RadioButton tk object you would use the child's tk property e.g. button_group = ButtonGroup(app) for radio_button in ButtonGroup.children: tk_radio_button = radio_button.tk","title":"ButtonGroup"},{"location":"buttongroup/#buttongroup","text":"__init__( self, master, options=[], selected=None, horizontal=False, command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None)","title":"ButtonGroup"},{"location":"buttongroup/#what-is-it","text":"The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option.","title":"What is it?"},{"location":"buttongroup/#how-do-i-make-one","text":"Create a ButtonGroup object like this: from guizero import App, ButtonGroup app = App() choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=\"cheese\") app.display()","title":"How do I make one?"},{"location":"buttongroup/#starting-parameters","text":"When you create a ButtonGroup object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets like this: choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"], selected=1) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options list or 2D List - No Either a list or a 2D list of [text, value] pairs. If a 2D list is specified, the first item in the pair will be displayed on the interface, and the second item will be a hidden value associated with this option. selected string - - The option that should be selected, if a value isn't provided the first option will be selected. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the selected option changes. args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid list [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal boolean False - Whether the buttons stack vertically or horizontally. (Defaults to vertical) visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"buttongroup/#methods","text":"You can call the following methods on an ButtonGroup object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the ButtonGroup. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget get_group_as_list() - list Returns a list containing all of the text/hidden value pairs from the ButtonGroup (useful for debugging) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), option (string) - Insert a new option in the ButtonGroup at index remove(option) item (string) Boolean Removes the first option from the ButtonGroup. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the selected option changes","title":"Methods"},{"location":"buttongroup/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget children List A list of the widgets in this container. [RadioButton, *] enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The hidden value associated with the currently selected option value_text string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Frame The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your ButtonGroup object is called choice you would write choice.value . You can set the property (for example choice.value = \"2\" ) or get the value of the property to use (for example print(choice.value) ).","title":"Properties"},{"location":"buttongroup/#examples","text":"Creating a ButtonGroup with a 2D list If you want to create a ButtonGroup object with your own hidden values you can specify a 2D list of options: from guizero import App, ButtonGroup, Text def update_text(): what_is_selected.value = activities.value app = App() activities = ButtonGroup(app, options=[ [\"Roller Skating\", \"skate\"], [\"White water rafting\", \"WWR\"], [\"Mountain climbing\", \"climb\"] ], selected=\"skate\", command=update_text) what_is_selected = Text(app, text=\"skate\") app.display()","title":"Examples"},{"location":"buttongroup/#using-buttongroup-tk-widgets","text":"Advanced users can gain internal access to the internal tkinter widgets used by ButtonGroup . For more information on using tkinter in combination with guizero see Using tkinter . The ButtonGroup widget contains a tkinter.Frame object, which frames multiple guizero RadioButton widgets. Each RadioButton widget contains a tkinter.Radiobutton object. The .children property returns the list of RadioButton widgets in the order they appear in the ButtonGroup : To access the internal RadioButton tk object you would use the child's tk property e.g. button_group = ButtonGroup(app) for radio_button in ButtonGroup.children: tk_radio_button = radio_button.tk","title":"Using ButtonGroup tk widgets"},{"location":"changelog/","text":"guizero 1.1.1 - 2020-11-27 PushButton image bug fix for macOS Documentation updates regarding how to use tk, particularly for ListBox widget Refactored .description property due to issue with TextBox widget Fix TextBox widget where you cant set the value if its disabled Removed bgcolor from App constructor which had previously been deprecated Resolved issue with Waffle and being able to click \"outside\" the waffle contributors martinohanlon , aajshaw 1.1.0 - 2019-10-25 Added ability to be able to change the grid of a widget at room time Added hide_text to TextBox for use with passwords Added open file and folder popups select_file and select_folder Changes to Text to better support cascading of text color, font and size Various documentation updates contributors martinohanlon , lawsie 1.0.0 - 2019-07-11 Previously deprecated methods have now been removed Resolved race condition in the repeat , cancel methods Refactored alerts (renamed pop-ups), they can now also be called from App & Window objects Added question pop-up Created windows MSI installer for guizero Deprecated App.on_closed method and replaced with App.when_closed property contributors martinohanlon , lawsie , MrYsLab , scotty3785 0.6.4 - 2019-05-08) Fixed TextBox command to be on key release Fix Text not inheriting properties Added add_tk_warning when inserting a tk widget into the wrong container Update docs contributors martinohanlon , hyle01 0.6.3 - 2019-04-18 ListBox scrollbar bug fix (again) Removed pillow requires dependency Added pillow as an extra dependency pip3 install guizero[images] Installation instructions update contributors martinohanlon , lawsie 0.6.2 - 2019-04-05 Ability to add tk widgets into a guizero app with .add_tk_widget() ListBox scrollbar bug fix MenuBar background colour bug fix setup.py changes to allow dunders to be accessed from guizero module contributors martinohanlon , lawsie 0.6.1 - 2019-03-08 New Drawing widget for creating \"drawings\" Added full screen support for App and Window Doc updates Minor bug fixes contributors martinohanlon , lawsie 0.6.0 - 2019-02-08 Refactoring of layout functions Enabled align for the auto layout width and height can now be set to \"fill\" Modified setup.py to restrict install to Python 3 only Minor bug fixes contributors martinohanlon , bennuttal , yeyeto2788 , knowledgejunkie , lawsie 0.5.4 - 2018-10-16 Fixed Box to size properly Added border to Box Added width and height to widget constructor Added resize method to all widgets Minor bug fixes contributors martinohanlon 0.5.3 - 2018-07-18 Various bug fixes wrapping multiline TextBox data ButtonGroup , ComboBox now allow 0 options at init Minimum pillow version is now 4.3.0 update method added to Add and Window contributors martinohanlon , scotty3785 , MrYsLab , bsimmo 0.5.2 - 2018-06-01 Refactoring of ButtonGroup , including API breaking change - if no hidden values are specified, ButtonGroup.value now returns the text value not a generate string number #178 A widgets properties bg , text_color , text_size , font , width , height can be restored by to their default by setting them to None #181 Slider is now sized properly when orientated vertically #186 Combo and ButtonGroup now support append , insert , remove , clear and depreciated add_option #180 Refactoring of class hierarchy Various bug fixes contributors martinohanlon 0.5.1 - 2018-05-14 App , Window , Box now support the following properties and will cascade them to widgets within them: bg text_color text_size font enabled Introduced ListBox Bug fixes relating to bg and text_color causing widgets to change colour when selected Minor bug fixes with CheckBox , Waffle and Combo Documentation fixes and updates contributors to this release martinohanlon , lawsie , Harlekuin 0.5.0 - 2018-04-10 v0.5.0 includes significant refactoring of the guizero code base and introduces many new features New image functionality introduced when PIL is installed: images can be passed as Tk.PhotoImage or PIL.Image objects as well as file paths more images types are supported animated images (gifs) are supported images are scaled when the size is changed ButtonGroup - selected is now optional, enabled properties now supported, value_text fixed Fixed multiple App bug Created Window class to support multi-window applications Added multiline and scrollbar functionality to TextBox Refactored guizero to introduce a class hierarchy making guizero wide code changes easier to implement Added the following events to all widgets, this should be considered experimental in this release: when_clicked when_left_button_pressed when_left_button_released when_right_button_pressed when_right_button_released when_key_pressed when_key_released when_mouse_enters when_mouse_leaves when_mouse_dragged Various minor bug fixes Automated tests have been introduced contributors to this release martinohanlon , scotty3785 , IDF31 , drussell1974 - ta very much :) 0.4.5 - 2018-03-04 colors can now be specified as either \"red\" , \"#ffffff\" , or (red, green, blue) change Picture image startup parameter to be optional updated Picture and PushButton errors and docs to show that PNG and GIF images can be used in Windows & Linux refactored Waffle resolving bugs that setting properties didnt change its appearance changed waffle so you can reference a pixel using waffle[x,y] added text_color , text_size and font properties to Slider added width and height properties to: Box ButtonGroup CheckBox Combo Picture Slider Text added width property to: TextBox contributors to this release Coal0 , martinohanlon , scotty3785 - :) 0.4.4 - 2018-02-12 made PushButton command optional Combo command functions can now have 0 arguments Waffle command functions can now have 0 arguments refactored command functions and added update_command to: ButtonGroup CheckBox Combo PushButton Slider Waffle refactored text_color , text_size and font properties and added them to: ButtonGroup Combo CheckBox PushButton Text TextBox refactored bg (background) and added to: Box ButtonGroup CheckBox Combo Picture PushButton Slider Text TextBox contributors to this release m4ddav3 , Coal0 , lawsie , martinohanlon - :) 0.4.3 - 2018-01-10 Minor features, bug fixes and internal refactoring added xspan , yspan to grid layout (Credit: penguintutor ) fixed show() for widgets in a grid layout added master , grid , align and visible properties to widgets added layout property to containers fixed Waffle height (Credit: scotty3785 ) minor doc updates 0.4.2 was never released due to some pypi / wheel problems 0.4.1 - 2017-12-28 Bug fixes and deployment test PushButton bug fixes added enabled property to widgets which support Enable / Disable documentation tidy up added build notes to documentation 0.4 - 2017-12-19 Thank you to everyone who has taken time to contribute code, suggest helpful improvements and report their use of the library. I am extremely grateful to the following people who have contributed pull requests since the last version: bcroston , bennuttall , Coal0 , martinohanlon and scotty3785 I am also very pleased to announce that martinohanlon has very kindly agreed to maintain guizero whilst I am on maternity leave, beginning December 2017. General changes: All classes rewritten with internal Tk objects rather than extending the Tk object, meaning you can access all Tk functionality as Object.tk.tkmethod() (Credit for idea: bennuttall ) Improved use of library with tab complete editors (e.g. ipython) \u2013 only the guizero properties and methods are listed so the list is shorter and more friendly. (Credit for idea: bennuttall ) [Bug fix] Grid layout now lays items out properly. Previously the x and y axes were flipped. (Whoops!) This fix will cause apps with a grid layout to look different, but now behave correctly. You may need to update old code as a result of this change. All classes now inherit from mixins, adding 9 new common methods usable on most widgets - after() , cancel() , destroy() , disable() , enable() , focus() , hide() , show() , repeat() , (Credit: Coal0 and martinohanlon ) The new repeat() method allows you to easily specify a repeated callback to a function, making it extremely easy to perform repetitive actions such as updating the GUI based on readings from a sensor. Documentation and examples have been improved and updated App: New constructor argument bg replaces deprecated bgcolor argument. If both are specified, bg overrides bgcolor . set_title() and bgcolor() methods are now deprecated and have been replaced by title and bg properties New additional properties width and height ButtonGroup: get() and set() methods are now deprecated and have been replaced by the value property New value_text property to get the text associated with the selected option CheckBox: get_text() , get_value() and change_text() methods are now deprecated and have been replaced by the value and text properties New toggle() method added Combo: get() and set() methods are now deprecated and have been replaced by the value property [Bug fix] set_default() now correctly resets the combo back to its originally specified value, whether this was the first option or a specified option Picture: set() method is now deprecated and has been replaced by the value property PushButton: set_text() method is now deprecated and has been replaced by the text property New properties for text_color , bg , font , text_size , height and width \u2013 make your buttons look pretty! Find out whether a button is pressed (1) or released (0) with the new value property New icon() method to set the icon of a button after it is created toggle_state() method deprecated and renamed to toggle() for consistency Slider: New value property for getting and setting the value of the slider Text: New constructor arguments text_color and bg color constructor argument now deprecated and replaced by text_color . If both are specified, text_color overrides color . get() , set() , color() , font_face() and font_size() methods are now deprecated, replaced by properties value , text_color , bg , font and size TextBox: get() and set() methods now deprecated and replaced by value property Waffle: All waffles will now have a memory. The remember constructor argument remains for backwards compatibility only and will be removed in a future release . You can now click on a Waffle, and specify a command to run when the Waffle is clicked on. The function given as the command should take two arguments as it will be passed the x, y coordinates of the pixel that was clicked. (Credit: scotty3785 ) Changed internal implementation of the Waffle so it should now be able to redraw more efficiently. (Credit: scotty3785 )","title":"Change log"},{"location":"changelog/#guizero","text":"","title":"guizero"},{"location":"changelog/#111-2020-11-27","text":"PushButton image bug fix for macOS Documentation updates regarding how to use tk, particularly for ListBox widget Refactored .description property due to issue with TextBox widget Fix TextBox widget where you cant set the value if its disabled Removed bgcolor from App constructor which had previously been deprecated Resolved issue with Waffle and being able to click \"outside\" the waffle contributors martinohanlon , aajshaw","title":"1.1.1 - 2020-11-27"},{"location":"changelog/#110-2019-10-25","text":"Added ability to be able to change the grid of a widget at room time Added hide_text to TextBox for use with passwords Added open file and folder popups select_file and select_folder Changes to Text to better support cascading of text color, font and size Various documentation updates contributors martinohanlon , lawsie","title":"1.1.0 - 2019-10-25"},{"location":"changelog/#100-2019-07-11","text":"Previously deprecated methods have now been removed Resolved race condition in the repeat , cancel methods Refactored alerts (renamed pop-ups), they can now also be called from App & Window objects Added question pop-up Created windows MSI installer for guizero Deprecated App.on_closed method and replaced with App.when_closed property contributors martinohanlon , lawsie , MrYsLab , scotty3785","title":"1.0.0 - 2019-07-11"},{"location":"changelog/#064-2019-05-08","text":"Fixed TextBox command to be on key release Fix Text not inheriting properties Added add_tk_warning when inserting a tk widget into the wrong container Update docs contributors martinohanlon , hyle01","title":"0.6.4 - 2019-05-08)"},{"location":"changelog/#063-2019-04-18","text":"ListBox scrollbar bug fix (again) Removed pillow requires dependency Added pillow as an extra dependency pip3 install guizero[images] Installation instructions update contributors martinohanlon , lawsie","title":"0.6.3 - 2019-04-18"},{"location":"changelog/#062-2019-04-05","text":"Ability to add tk widgets into a guizero app with .add_tk_widget() ListBox scrollbar bug fix MenuBar background colour bug fix setup.py changes to allow dunders to be accessed from guizero module contributors martinohanlon , lawsie","title":"0.6.2 - 2019-04-05"},{"location":"changelog/#061-2019-03-08","text":"New Drawing widget for creating \"drawings\" Added full screen support for App and Window Doc updates Minor bug fixes contributors martinohanlon , lawsie","title":"0.6.1 - 2019-03-08"},{"location":"changelog/#060-2019-02-08","text":"Refactoring of layout functions Enabled align for the auto layout width and height can now be set to \"fill\" Modified setup.py to restrict install to Python 3 only Minor bug fixes contributors martinohanlon , bennuttal , yeyeto2788 , knowledgejunkie , lawsie","title":"0.6.0 - 2019-02-08"},{"location":"changelog/#054-2018-10-16","text":"Fixed Box to size properly Added border to Box Added width and height to widget constructor Added resize method to all widgets Minor bug fixes contributors martinohanlon","title":"0.5.4 - 2018-10-16"},{"location":"changelog/#053-2018-07-18","text":"Various bug fixes wrapping multiline TextBox data ButtonGroup , ComboBox now allow 0 options at init Minimum pillow version is now 4.3.0 update method added to Add and Window contributors martinohanlon , scotty3785 , MrYsLab , bsimmo","title":"0.5.3 - 2018-07-18"},{"location":"changelog/#052-2018-06-01","text":"Refactoring of ButtonGroup , including API breaking change - if no hidden values are specified, ButtonGroup.value now returns the text value not a generate string number #178 A widgets properties bg , text_color , text_size , font , width , height can be restored by to their default by setting them to None #181 Slider is now sized properly when orientated vertically #186 Combo and ButtonGroup now support append , insert , remove , clear and depreciated add_option #180 Refactoring of class hierarchy Various bug fixes contributors martinohanlon","title":"0.5.2 - 2018-06-01"},{"location":"changelog/#051-2018-05-14","text":"App , Window , Box now support the following properties and will cascade them to widgets within them: bg text_color text_size font enabled Introduced ListBox Bug fixes relating to bg and text_color causing widgets to change colour when selected Minor bug fixes with CheckBox , Waffle and Combo Documentation fixes and updates contributors to this release martinohanlon , lawsie , Harlekuin","title":"0.5.1 - 2018-05-14"},{"location":"changelog/#050-2018-04-10","text":"v0.5.0 includes significant refactoring of the guizero code base and introduces many new features New image functionality introduced when PIL is installed: images can be passed as Tk.PhotoImage or PIL.Image objects as well as file paths more images types are supported animated images (gifs) are supported images are scaled when the size is changed ButtonGroup - selected is now optional, enabled properties now supported, value_text fixed Fixed multiple App bug Created Window class to support multi-window applications Added multiline and scrollbar functionality to TextBox Refactored guizero to introduce a class hierarchy making guizero wide code changes easier to implement Added the following events to all widgets, this should be considered experimental in this release: when_clicked when_left_button_pressed when_left_button_released when_right_button_pressed when_right_button_released when_key_pressed when_key_released when_mouse_enters when_mouse_leaves when_mouse_dragged Various minor bug fixes Automated tests have been introduced contributors to this release martinohanlon , scotty3785 , IDF31 , drussell1974 - ta very much :)","title":"0.5.0 - 2018-04-10"},{"location":"changelog/#045-2018-03-04","text":"colors can now be specified as either \"red\" , \"#ffffff\" , or (red, green, blue) change Picture image startup parameter to be optional updated Picture and PushButton errors and docs to show that PNG and GIF images can be used in Windows & Linux refactored Waffle resolving bugs that setting properties didnt change its appearance changed waffle so you can reference a pixel using waffle[x,y] added text_color , text_size and font properties to Slider added width and height properties to: Box ButtonGroup CheckBox Combo Picture Slider Text added width property to: TextBox contributors to this release Coal0 , martinohanlon , scotty3785 - :)","title":"0.4.5 - 2018-03-04"},{"location":"changelog/#044-2018-02-12","text":"made PushButton command optional Combo command functions can now have 0 arguments Waffle command functions can now have 0 arguments refactored command functions and added update_command to: ButtonGroup CheckBox Combo PushButton Slider Waffle refactored text_color , text_size and font properties and added them to: ButtonGroup Combo CheckBox PushButton Text TextBox refactored bg (background) and added to: Box ButtonGroup CheckBox Combo Picture PushButton Slider Text TextBox contributors to this release m4ddav3 , Coal0 , lawsie , martinohanlon - :)","title":"0.4.4 - 2018-02-12"},{"location":"changelog/#043-2018-01-10","text":"Minor features, bug fixes and internal refactoring added xspan , yspan to grid layout (Credit: penguintutor ) fixed show() for widgets in a grid layout added master , grid , align and visible properties to widgets added layout property to containers fixed Waffle height (Credit: scotty3785 ) minor doc updates 0.4.2 was never released due to some pypi / wheel problems","title":"0.4.3 - 2018-01-10"},{"location":"changelog/#041-2017-12-28","text":"Bug fixes and deployment test PushButton bug fixes added enabled property to widgets which support Enable / Disable documentation tidy up added build notes to documentation","title":"0.4.1 - 2017-12-28"},{"location":"changelog/#04-2017-12-19","text":"Thank you to everyone who has taken time to contribute code, suggest helpful improvements and report their use of the library. I am extremely grateful to the following people who have contributed pull requests since the last version: bcroston , bennuttall , Coal0 , martinohanlon and scotty3785 I am also very pleased to announce that martinohanlon has very kindly agreed to maintain guizero whilst I am on maternity leave, beginning December 2017. General changes: All classes rewritten with internal Tk objects rather than extending the Tk object, meaning you can access all Tk functionality as Object.tk.tkmethod() (Credit for idea: bennuttall ) Improved use of library with tab complete editors (e.g. ipython) \u2013 only the guizero properties and methods are listed so the list is shorter and more friendly. (Credit for idea: bennuttall ) [Bug fix] Grid layout now lays items out properly. Previously the x and y axes were flipped. (Whoops!) This fix will cause apps with a grid layout to look different, but now behave correctly. You may need to update old code as a result of this change. All classes now inherit from mixins, adding 9 new common methods usable on most widgets - after() , cancel() , destroy() , disable() , enable() , focus() , hide() , show() , repeat() , (Credit: Coal0 and martinohanlon ) The new repeat() method allows you to easily specify a repeated callback to a function, making it extremely easy to perform repetitive actions such as updating the GUI based on readings from a sensor. Documentation and examples have been improved and updated App: New constructor argument bg replaces deprecated bgcolor argument. If both are specified, bg overrides bgcolor . set_title() and bgcolor() methods are now deprecated and have been replaced by title and bg properties New additional properties width and height ButtonGroup: get() and set() methods are now deprecated and have been replaced by the value property New value_text property to get the text associated with the selected option CheckBox: get_text() , get_value() and change_text() methods are now deprecated and have been replaced by the value and text properties New toggle() method added Combo: get() and set() methods are now deprecated and have been replaced by the value property [Bug fix] set_default() now correctly resets the combo back to its originally specified value, whether this was the first option or a specified option Picture: set() method is now deprecated and has been replaced by the value property PushButton: set_text() method is now deprecated and has been replaced by the text property New properties for text_color , bg , font , text_size , height and width \u2013 make your buttons look pretty! Find out whether a button is pressed (1) or released (0) with the new value property New icon() method to set the icon of a button after it is created toggle_state() method deprecated and renamed to toggle() for consistency Slider: New value property for getting and setting the value of the slider Text: New constructor arguments text_color and bg color constructor argument now deprecated and replaced by text_color . If both are specified, text_color overrides color . get() , set() , color() , font_face() and font_size() methods are now deprecated, replaced by properties value , text_color , bg , font and size TextBox: get() and set() methods now deprecated and replaced by value property Waffle: All waffles will now have a memory. The remember constructor argument remains for backwards compatibility only and will be removed in a future release . You can now click on a Waffle, and specify a command to run when the Waffle is clicked on. The function given as the command should take two arguments as it will be passed the x, y coordinates of the pixel that was clicked. (Credit: scotty3785 ) Changed internal implementation of the Waffle so it should now be able to redraw more efficiently. (Credit: scotty3785 )","title":"0.4 - 2017-12-19"},{"location":"checkbox/","text":"CheckBox __init__( self, master, text=\"\", command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None) What is it? The CheckBox object displays a check box to allow an option to be ticked or un-ticked. How do I make one? Create a CheckBox object like this: from guizero import App, CheckBox app = App() checkbox = CheckBox(app, text=\"Add extra glitter\") app.display() Starting parameters When you create a CheckBox object you must specify master and text and you can specify any of the optional parameters. Specify parameters in the brackets, like this: checkbox = CheckBox(app, text=\"Add extra glitter\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs text string \"\" No The text to display next to the check box align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when this checkbox is ticked/unticked args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on a CheckBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Switches the CheckBox to the opposite of its current value. i.e. if it is ticked, untick it and vice versa update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the checkbox is ticked/unticked Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text string The text associated with the checkbox value int 1 if the CheckBox is ticked or 0 if it is not ticked visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Checkbutton The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your CheckBox object is called checkbox you would write checkbox.value . You can set the property (for example checkbox.value = 1 ) or get the value of the property to use (for example print(checkbox.value) ). Examples Creating multiple CheckBoxes Create multiple CheckBoxes like this. from guizero import App, CheckBox app = App() glitter = CheckBox(app, text=\"Add glitter\") sparkles = CheckBox(app, text=\"Add sparkles\") app.display() Calling a function when a CheckBox value changes You can call a function when the value of a CheckBox changes (becomes checked or unchecked). In this particular example all three CheckBoxes call the same function, but it is possible for each CheckBox object to call a different function. from guizero import App, Text, CheckBox, TextBox def calculate_extras(): total = 0 if syrup.value == 1: total += 20 if sprinkles.value == 1: total += 10 if cream.value == 1: total += 50 cost.value = total app = App() questions = Text(app, text=\"What would you like with your coffee?\") syrup = CheckBox(app, text=\"Caramel syrup (20p)\", command=calculate_extras) sprinkles = CheckBox(app, text=\"Chocolate sprinkles (10p)\", command=calculate_extras) cream = CheckBox(app, text=\"Whipped cream (50p)\", command=calculate_extras) cost_of_extras = Text(app, text=\"Cost of extras:\") cost = TextBox(app, text=\"0\") app.display()","title":"CheckBox"},{"location":"checkbox/#checkbox","text":"__init__( self, master, text=\"\", command=None, grid=None, align=None, args=None, visible=True, enabled=None, width=None, height=None)","title":"CheckBox"},{"location":"checkbox/#what-is-it","text":"The CheckBox object displays a check box to allow an option to be ticked or un-ticked.","title":"What is it?"},{"location":"checkbox/#how-do-i-make-one","text":"Create a CheckBox object like this: from guizero import App, CheckBox app = App() checkbox = CheckBox(app, text=\"Add extra glitter\") app.display()","title":"How do I make one?"},{"location":"checkbox/#starting-parameters","text":"When you create a CheckBox object you must specify master and text and you can specify any of the optional parameters. Specify parameters in the brackets, like this: checkbox = CheckBox(app, text=\"Add extra glitter\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs text string \"\" No The text to display next to the check box align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when this checkbox is ticked/unticked args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"checkbox/#methods","text":"You can call the following methods on a CheckBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Switches the CheckBox to the opposite of its current value. i.e. if it is ticked, untick it and vice versa update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the checkbox is ticked/unticked","title":"Methods"},{"location":"checkbox/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text string The text associated with the checkbox value int 1 if the CheckBox is ticked or 0 if it is not ticked visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Checkbutton The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your CheckBox object is called checkbox you would write checkbox.value . You can set the property (for example checkbox.value = 1 ) or get the value of the property to use (for example print(checkbox.value) ).","title":"Properties"},{"location":"checkbox/#examples","text":"Creating multiple CheckBoxes Create multiple CheckBoxes like this. from guizero import App, CheckBox app = App() glitter = CheckBox(app, text=\"Add glitter\") sparkles = CheckBox(app, text=\"Add sparkles\") app.display() Calling a function when a CheckBox value changes You can call a function when the value of a CheckBox changes (becomes checked or unchecked). In this particular example all three CheckBoxes call the same function, but it is possible for each CheckBox object to call a different function. from guizero import App, Text, CheckBox, TextBox def calculate_extras(): total = 0 if syrup.value == 1: total += 20 if sprinkles.value == 1: total += 10 if cream.value == 1: total += 50 cost.value = total app = App() questions = Text(app, text=\"What would you like with your coffee?\") syrup = CheckBox(app, text=\"Caramel syrup (20p)\", command=calculate_extras) sprinkles = CheckBox(app, text=\"Chocolate sprinkles (10p)\", command=calculate_extras) cream = CheckBox(app, text=\"Whipped cream (50p)\", command=calculate_extras) cost_of_extras = Text(app, text=\"Cost of extras:\") cost = TextBox(app, text=\"0\") app.display()","title":"Examples"},{"location":"colors/","text":"Colors (or Colo u rs) You can set colors in guizero using: the name of the color - white a #rgb hex value - #ffffff a list of rgb values - (255,255,255) Colors can be used as either starting parameters, for example: app = App(bg = \"red\") app = App(bg = \"#ff0000\") app = App(bg = (255, 0, 0)) or as properties, for example: text = Text(app, text = \"hi\") text.text_color = \"green\" text.text_color = \"#00ff00\" text.text_color = (0, 255, 0) If a color is set using a list of rgb values ( (255,255,255) ) it will be returned as an #rgb hex value ( #ffffff ) Color names Some color names can be given as strings, for example white black red green blue yellow A complete list of color names is available at wiki.tcl.tk/37701 rgb hex value A rgb color value must start with a # and 6 characters following, 2 each for the red, green and blue value in hex. Each value must be 00 - ff . Here are some examples: white = #ffffff black = #000000 red = #ff0000 green = #00ff00 blue = #0000ff yellow = #ffff00 You can mix your own color by changing the red, green and blue values. There is a RGB calculator application at https://www.w3schools.com/colors/colors_rgb.asp where you can create your own color and get the #rrggbb value. rgb list The (red, green, blue) list color must contain three elements in the order red, green, blue. Each value must be between 0 - 255. Here are some examples: white = (255, 255, 255) black = (0, 0, 0) red = (255, 0, 0) green = (0, 255, 0) blue = (0, 0, 255) yellow = (255, 255, 0)","title":"Colors"},{"location":"colors/#colors-or-colours","text":"You can set colors in guizero using: the name of the color - white a #rgb hex value - #ffffff a list of rgb values - (255,255,255) Colors can be used as either starting parameters, for example: app = App(bg = \"red\") app = App(bg = \"#ff0000\") app = App(bg = (255, 0, 0)) or as properties, for example: text = Text(app, text = \"hi\") text.text_color = \"green\" text.text_color = \"#00ff00\" text.text_color = (0, 255, 0) If a color is set using a list of rgb values ( (255,255,255) ) it will be returned as an #rgb hex value ( #ffffff )","title":"Colors (or Colours)"},{"location":"colors/#color-names","text":"Some color names can be given as strings, for example white black red green blue yellow A complete list of color names is available at wiki.tcl.tk/37701","title":"Color names"},{"location":"colors/#rgb-hex-value","text":"A rgb color value must start with a # and 6 characters following, 2 each for the red, green and blue value in hex. Each value must be 00 - ff . Here are some examples: white = #ffffff black = #000000 red = #ff0000 green = #00ff00 blue = #0000ff yellow = #ffff00 You can mix your own color by changing the red, green and blue values. There is a RGB calculator application at https://www.w3schools.com/colors/colors_rgb.asp where you can create your own color and get the #rrggbb value.","title":"rgb hex value"},{"location":"colors/#rgb-list","text":"The (red, green, blue) list color must contain three elements in the order red, green, blue. Each value must be between 0 - 255. Here are some examples: white = (255, 255, 255) black = (0, 0, 0) red = (255, 0, 0) green = (0, 255, 0) blue = (0, 0, 255) yellow = (255, 255, 0)","title":"rgb list"},{"location":"combo/","text":"Combo __init__( self, master, options=[], selected=None, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Combo object displays a drop down box allowing a single option to be selected from a list of options. How do I make one? Create a Combo object like this: from guizero import App, Combo app = App() combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display() Starting parameters When you create a Combo object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options List [] No A list of options to display selected string None No The option to select by default align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the Combo will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on a Combo object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the Combo. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Removes all options from the Combo box destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), item (string) - Insert a new option in the Combo at index remove(option) item (string) Boolean Removes the first option from the Combo. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget select_default() - - Resets the combo box so that the first item is selected show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.OptionMenu The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your Combo object is called combo you would write combo.value . You can set the property (for example combo.value = \"Chicken\" ) or get the value of the property to use (for example print(combo.value) ). Examples Calling a function when the value selected changes You can call a function when the selected value in a Combo object changes. The function you call can take either zero or one argument, if the function takes one argument it will automatically be passed a string containing the currently selected value from the Combo object. from guizero import App, Text, Combo def you_chose(selected_value): if selected_value == \"Tiny goblet\": result.value = \"You chose...wisely\" else: result.value = \"You chose...poorly\" app = App() instructions = Text(app, text=\"Choose a goblet\") combo = Combo(app, options=[\"\", \"Huge golden goblet\", \"Jewel encrusted goblet\", \"Tiny goblet\"], command=you_chose) result = Text(app) app.display()","title":"Combo"},{"location":"combo/#combo","text":"__init__( self, master, options=[], selected=None, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Combo"},{"location":"combo/#what-is-it","text":"The Combo object displays a drop down box allowing a single option to be selected from a list of options.","title":"What is it?"},{"location":"combo/#how-do-i-make-one","text":"Create a Combo object like this: from guizero import App, Combo app = App() combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display()","title":"How do I make one?"},{"location":"combo/#starting-parameters","text":"When you create a Combo object you must specify a master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: combo = Combo(app, options=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs options List [] No A list of options to display selected string None No The option to select by default align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the Combo will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"combo/#methods","text":"You can call the following methods on a Combo object. Method Takes Returns Description append(option) item (string) - Appends a new option to the end of the Combo. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Removes all options from the Combo box destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, option) index (int), item (string) - Insert a new option in the Combo at index remove(option) item (string) Boolean Removes the first option from the Combo. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget select_default() - - Resets the combo box so that the first item is selected show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected.","title":"Methods"},{"location":"combo/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs value string The text associated with the currently selected option visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.OptionMenu The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your Combo object is called combo you would write combo.value . You can set the property (for example combo.value = \"Chicken\" ) or get the value of the property to use (for example print(combo.value) ).","title":"Properties"},{"location":"combo/#examples","text":"Calling a function when the value selected changes You can call a function when the selected value in a Combo object changes. The function you call can take either zero or one argument, if the function takes one argument it will automatically be passed a string containing the currently selected value from the Combo object. from guizero import App, Text, Combo def you_chose(selected_value): if selected_value == \"Tiny goblet\": result.value = \"You chose...wisely\" else: result.value = \"You chose...poorly\" app = App() instructions = Text(app, text=\"Choose a goblet\") combo = Combo(app, options=[\"\", \"Huge golden goblet\", \"Jewel encrusted goblet\", \"Tiny goblet\"], command=you_chose) result = Text(app) app.display()","title":"Examples"},{"location":"commands/","text":"Commands Widgets in guizero can be given a command when created, which can be used to call a function when the widget is used. By using commands you can make your GUI change and take actions when the user interacts with it, for example by clicking a button, selecting an option or typing a message. Example This code will display hello world when the button is pressed: from guizero import App, Text, PushButton def say_hello(): text.value = \"hello world\" app = App() text = Text(app) button = PushButton(app, command=say_hello) app.display()","title":"Commands"},{"location":"commands/#commands","text":"Widgets in guizero can be given a command when created, which can be used to call a function when the widget is used. By using commands you can make your GUI change and take actions when the user interacts with it, for example by clicking a button, selecting an option or typing a message.","title":"Commands"},{"location":"commands/#example","text":"This code will display hello world when the button is pressed: from guizero import App, Text, PushButton def say_hello(): text.value = \"hello world\" app = App() text = Text(app) button = PushButton(app, command=say_hello) app.display()","title":"Example"},{"location":"contributing/","text":"Contributing Contributions are very welcome; be that changes, bug fixing, issue resolution or support. Issues All issues should be raised on github.com/lawsie/guizero/issues Code When providing code changes please: use the dev branch as the base for all changes create a single pull request for each fix / addition follow the existing coding style provide documentation for all changes as markdown in /docs-src provide tests for all changes in /test","title":"Notes"},{"location":"contributing/#contributing","text":"Contributions are very welcome; be that changes, bug fixing, issue resolution or support.","title":"Contributing"},{"location":"contributing/#issues","text":"All issues should be raised on github.com/lawsie/guizero/issues","title":"Issues"},{"location":"contributing/#code","text":"When providing code changes please: use the dev branch as the base for all changes create a single pull request for each fix / addition follow the existing coding style provide documentation for all changes as markdown in /docs-src provide tests for all changes in /test","title":"Code"},{"location":"deployment/","text":"Deploy Notes on how to deploy guizero (on Windows). Prepare Update version number in guizero\\__init__.py Update version number in docs-src\\docs\\about.md Update version number for Windows MSI installer in docs-src\\docs\\index.md Update changelog.md in docs Python library Install locally: cd guizero python setup.py install Build for deployment: cd guizero python setup.py sdist python setup.py bdist_wheel python setup.py bdist_msi --plat-name=amd64 python setup.py bdist_msi --plat-name=win32 Upload to pypi: cd guizero twine upload dist/* --skip-existing Documents Build: cd guizero/docs-src mkdocs build Copy to docs : cd guizero xcopy docs-src\\site\\* docs /E Promote and tag release on github Push all changes to master . Create a new release on github named 0.0.0 . Upload Windows MSI installers named guizero-0.0.0.amd64.msi and guizero-0.0.0.win32.msi to the release.","title":"Deploying"},{"location":"deployment/#deploy","text":"Notes on how to deploy guizero (on Windows).","title":"Deploy"},{"location":"deployment/#prepare","text":"Update version number in guizero\\__init__.py Update version number in docs-src\\docs\\about.md Update version number for Windows MSI installer in docs-src\\docs\\index.md Update changelog.md in docs","title":"Prepare"},{"location":"deployment/#python-library","text":"Install locally: cd guizero python setup.py install Build for deployment: cd guizero python setup.py sdist python setup.py bdist_wheel python setup.py bdist_msi --plat-name=amd64 python setup.py bdist_msi --plat-name=win32 Upload to pypi: cd guizero twine upload dist/* --skip-existing","title":"Python library"},{"location":"deployment/#documents","text":"Build: cd guizero/docs-src mkdocs build Copy to docs : cd guizero xcopy docs-src\\site\\* docs /E","title":"Documents"},{"location":"deployment/#promote-and-tag-release-on-github","text":"Push all changes to master . Create a new release on github named 0.0.0 . Upload Windows MSI installers named guizero-0.0.0.amd64.msi and guizero-0.0.0.win32.msi to the release.","title":"Promote and tag release on github"},{"location":"development/","text":"Development Notes on how to develop guizero (on Windows). Setup Upgrade pip: python.exe -m pip install pip --upgrade Install / upgrade pre-requisites: pip install mkdocs wheel twine virtualenv pytest pillow --upgrade Python library Create a virtual environment (not essential, but a good idea!): virtualenv guizero-[versionno] cd guizero-[versionno] Activate your virtual environment: Scripts\\activate Checkout and install guizero for development: git clone https://github.com/lawsie/guizero cd guizero git checkout dev python setup.py develop When you have finished your development, deactivate your virtual environment: Scripts\\deactivate Tests To run the automated tests: cd guizero\\test pytest -v If running the tests inside a virtual environment you will need to install pytest in that virtual environment. pip install pytest Note - tkinter can error when running the tests usually when the interpreter doesn't start properly, it doesn't seem to like being initialised and destroyed hundreds of times, I suspect a file locking issue as you don't see the problem on Linux. So sometimes you might get a test fail with an error like This probably means that tk wasn't installed properly. . Just re-run the last failed errors! pytest --lf -v Documents Test documents by serving up MkDocs: cd guizero\\docs-src mkdocs serve Open http://127.0.0.1:8000/","title":"Developing"},{"location":"development/#development","text":"Notes on how to develop guizero (on Windows).","title":"Development"},{"location":"development/#setup","text":"Upgrade pip: python.exe -m pip install pip --upgrade Install / upgrade pre-requisites: pip install mkdocs wheel twine virtualenv pytest pillow --upgrade","title":"Setup"},{"location":"development/#python-library","text":"Create a virtual environment (not essential, but a good idea!): virtualenv guizero-[versionno] cd guizero-[versionno] Activate your virtual environment: Scripts\\activate Checkout and install guizero for development: git clone https://github.com/lawsie/guizero cd guizero git checkout dev python setup.py develop When you have finished your development, deactivate your virtual environment: Scripts\\deactivate","title":"Python library"},{"location":"development/#tests","text":"To run the automated tests: cd guizero\\test pytest -v If running the tests inside a virtual environment you will need to install pytest in that virtual environment. pip install pytest Note - tkinter can error when running the tests usually when the interpreter doesn't start properly, it doesn't seem to like being initialised and destroyed hundreds of times, I suspect a file locking issue as you don't see the problem on Linux. So sometimes you might get a test fail with an error like This probably means that tk wasn't installed properly. . Just re-run the last failed errors! pytest --lf -v","title":"Tests"},{"location":"development/#documents","text":"Test documents by serving up MkDocs: cd guizero\\docs-src mkdocs serve Open http://127.0.0.1:8000/","title":"Documents"},{"location":"drawing/","text":"Drawing __init__( self, master, width=100, height=100, grid=None, align=None, visible=True, enabled=None) What is it? The Drawing object allows shapes, images and text to be created. How do I make one? Create a Drawing object and draw a blue rectangle 50x50 pixels like this: from guizero import App, Drawing app = App() drawing = Drawing(app) drawing.rectangle(10, 10, 60, 60, color=\"blue\") app.display() Starting parameters When you create a Drawing object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: drawing = Drawing(app, height=300, width=300) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master Methods You can call the following methods on a Drawing object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the drawing delete() id (int) - - Deletes an \"object\" (line, triangle, image, etc) from the drawing. destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(self, x, y, image, width=None, height=None): x (int), y (int), image (str), width (int), height (int) Id Inserts an image into the drawing at the specified position and returns the id of the image created. line(x1, y1, x2, y2, color=\"black\", width=1) x1 (int), y1 (int), x2 (int), y2 (int), color (str), width (int) Id Draws a line between 2 points and returns the id of the line created. oval(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws an oval between 2 points and returns the id of the shape created. polygon(*coords, color=\"black\", outline=False, outline_color=\"black\") coords (list int), color (str), outline (int), outline_color (str) Id Draws a polygon between any number of coordinates passed as pairs of x, y and returns the id of the shape created. rectangle(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws a rectangle between 2 points and returns the id of the shape created. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden text(x, y, text, color=\"black\", font=None, size=None, max_width=None) x (int), y (int), text (str), color (str), font (str), size (str), max_width (int) Id Inserts text into the drawing at the specified position and returns the id of the shape created. triangle(x1, y1, x2, y2, x3, y3, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), x3 (int), y3 (int), color (str), outline (int), outline_color (str) Id Draws a triangle between 3 points and returns the id of the shape created. update_command(command) command (function name) - Updates the function to call when a different option is selected. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs tk tkinter.canvas The internal tkinter object, see Using tkinter visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" Refer to a property as .property . For example, if your Drawing object is called drawing you would write drawing.bg . You can set the property (for example drawing.bg = \"blue\" ) or get the value of the property to use (for example print(drawing.bg) ). Examples Draw a robot face Use a rectangle for the face, ovals for the eyes, a triangle for the nose and lines for the mouth. from guizero import App, Drawing a = App() # create drawing object d = Drawing(a, width=220, height=220) d.rectangle(10, 10, 210, 210, color=\"light blue\") d.oval(30, 30, 50, 50, color=\"white\", outline=True) d.oval(170, 30, 190, 50, color=\"white\", outline=True) d.triangle(110, 90, 120, 110, 100, 110, color=\"black\") d.line(50, 180, 50, 160, color=\"red\", width=5) d.line(50, 180, 170, 180, color=\"red\", width=5) d.line(170, 180, 170, 160, color=\"red\", width=5) a.display()","title":"Drawing"},{"location":"drawing/#drawing","text":"__init__( self, master, width=100, height=100, grid=None, align=None, visible=True, enabled=None)","title":"Drawing"},{"location":"drawing/#what-is-it","text":"The Drawing object allows shapes, images and text to be created.","title":"What is it?"},{"location":"drawing/#how-do-i-make-one","text":"Create a Drawing object and draw a blue rectangle 50x50 pixels like this: from guizero import App, Drawing app = App() drawing = Drawing(app) drawing.rectangle(10, 10, 60, 60, color=\"blue\") app.display()","title":"How do I make one?"},{"location":"drawing/#starting-parameters","text":"When you create a Drawing object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: drawing = Drawing(app, height=300, width=300) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master","title":"Starting parameters"},{"location":"drawing/#methods","text":"You can call the following methods on a Drawing object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the drawing delete() id (int) - - Deletes an \"object\" (line, triangle, image, etc) from the drawing. destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(self, x, y, image, width=None, height=None): x (int), y (int), image (str), width (int), height (int) Id Inserts an image into the drawing at the specified position and returns the id of the image created. line(x1, y1, x2, y2, color=\"black\", width=1) x1 (int), y1 (int), x2 (int), y2 (int), color (str), width (int) Id Draws a line between 2 points and returns the id of the line created. oval(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws an oval between 2 points and returns the id of the shape created. polygon(*coords, color=\"black\", outline=False, outline_color=\"black\") coords (list int), color (str), outline (int), outline_color (str) Id Draws a polygon between any number of coordinates passed as pairs of x, y and returns the id of the shape created. rectangle(x1, y1, x2, y2, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), color (str), outline (int), outline_color (str) Id Draws a rectangle between 2 points and returns the id of the shape created. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden text(x, y, text, color=\"black\", font=None, size=None, max_width=None) x (int), y (int), text (str), color (str), font (str), size (str), max_width (int) Id Inserts text into the drawing at the specified position and returns the id of the shape created. triangle(x1, y1, x2, y2, x3, y3, color=\"black\", outline=False, outline_color=\"black\") x1 (int), y1 (int), x2 (int), y2 (int), x3 (int), y3 (int), color (str), outline (int), outline_color (str) Id Draws a triangle between 3 points and returns the id of the shape created. update_command(command) command (function name) - Updates the function to call when a different option is selected.","title":"Methods"},{"location":"drawing/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs tk tkinter.canvas The internal tkinter object, see Using tkinter visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" Refer to a property as .property . For example, if your Drawing object is called drawing you would write drawing.bg . You can set the property (for example drawing.bg = \"blue\" ) or get the value of the property to use (for example print(drawing.bg) ).","title":"Properties"},{"location":"drawing/#examples","text":"Draw a robot face Use a rectangle for the face, ovals for the eyes, a triangle for the nose and lines for the mouth. from guizero import App, Drawing a = App() # create drawing object d = Drawing(a, width=220, height=220) d.rectangle(10, 10, 210, 210, color=\"light blue\") d.oval(30, 30, 50, 50, color=\"white\", outline=True) d.oval(170, 30, 190, 50, color=\"white\", outline=True) d.triangle(110, 90, 120, 110, 100, 110, color=\"black\") d.line(50, 180, 50, 160, color=\"red\", width=5) d.line(50, 180, 170, 180, color=\"red\", width=5) d.line(170, 180, 170, 160, color=\"red\", width=5) a.display()","title":"Examples"},{"location":"events/","text":"Events Custom events can be added to guizero widgets to call functions when the user takes the following actions: when clicked - when_clicked when the left mouse button is pressed - when_left_button_pressed when the left mouse button is released - when_left_button_released when the right mouse button is pressed - when_right_button_pressed when the right mouse button is released - when_right_button_released when a key is pressed - when_key_pressed when a key is released - when_key_released when the mouse enters a widget - when_mouse_enters when the mouse leaves a widget - when_mouse_leaves when the mouse is dragged across a widget - when_mouse_dragged Events are set by assigning them to a function: def do_this(): print(\"The widget was clicked\") widget.when_clicked = do_this Event Data The function which is called can also accept a parameter and will be passed data about the event which occured. The event data returned has: widget - the guizero widget which raised the event tk_event - the tkinter event object key - the key which raised the event x - the mouse's x position relative to the widget when the event occured y - the mouse's y position relative to the widget when the event occured display_x - the mouse's x position on the display when the event occured display_y - the mouse's y position on the display when the event occured def clicked(event_data): print(\"widget clicked = \" + event_data.widget) print(\"mouse position = \" + event_data.x + \".\" + event_data.y) widget.when_clicked = clicked Example Highlight a text box widget by changing its background color ( bg ) when the mouse is hovering over it. from guizero import App, TextBox def highlight(): text_box.bg = \"lightblue\" def lowlight(): text_box.bg = \"white\" app = App() text_box = TextBox(app) # When the mouse enters the TextBox text_box.when_mouse_enters = highlight # When the mouse leaves the TextBox text_box.when_mouse_leaves = lowlight app.display()","title":"Events"},{"location":"events/#events","text":"Custom events can be added to guizero widgets to call functions when the user takes the following actions: when clicked - when_clicked when the left mouse button is pressed - when_left_button_pressed when the left mouse button is released - when_left_button_released when the right mouse button is pressed - when_right_button_pressed when the right mouse button is released - when_right_button_released when a key is pressed - when_key_pressed when a key is released - when_key_released when the mouse enters a widget - when_mouse_enters when the mouse leaves a widget - when_mouse_leaves when the mouse is dragged across a widget - when_mouse_dragged Events are set by assigning them to a function: def do_this(): print(\"The widget was clicked\") widget.when_clicked = do_this","title":"Events"},{"location":"events/#event-data","text":"The function which is called can also accept a parameter and will be passed data about the event which occured. The event data returned has: widget - the guizero widget which raised the event tk_event - the tkinter event object key - the key which raised the event x - the mouse's x position relative to the widget when the event occured y - the mouse's y position relative to the widget when the event occured display_x - the mouse's x position on the display when the event occured display_y - the mouse's y position on the display when the event occured def clicked(event_data): print(\"widget clicked = \" + event_data.widget) print(\"mouse position = \" + event_data.x + \".\" + event_data.y) widget.when_clicked = clicked","title":"Event Data"},{"location":"events/#example","text":"Highlight a text box widget by changing its background color ( bg ) when the mouse is hovering over it. from guizero import App, TextBox def highlight(): text_box.bg = \"lightblue\" def lowlight(): text_box.bg = \"white\" app = App() text_box = TextBox(app) # When the mouse enters the TextBox text_box.when_mouse_enters = highlight # When the mouse leaves the TextBox text_box.when_mouse_leaves = lowlight app.display()","title":"Example"},{"location":"gettinghelp/","text":"Getting help You may encounter a problem when using guizero, so here are some ways you can get help to solve your problem. Getting help If you have a question about your guizero program it is a good idea to join a community to ask for support: Raspberry Pi Forums - some people post questions about guizero on these forums and other members of the community step in to help. The creators of guizero periodically check the Python forum. Stack Overflow - a popular site for techy questions Computing at School - a useful site for teachers If you would like to read guides and resources for guizero there are many freely available: Getting started with GUIs - a beginners guide to guizero by the Raspberry Pi Foundation Python guizero video - a series of videos by Devon Schafer on using guizero. Example programs - some example programs to get you going. Using guizero with hardware - Ben Nuttall's projects using guizero combined with hardware Cat name generator - materials for a kids workshop, first run at the Cotswold Jam Name your pet - article on page 42 of Hello World magazine issue 2. Bugs and feature requests Like many Python libraries, guizero has a GitHub repository where you can add issues. These issues come under two headings: You found a bug in guizero You would like to request we consider including a new feature We look at and respond to all issues created on GitHub. However, we ask that you only create issues for bugs and feature requests, rather than support, as we do not have time to answer everything :)","title":"Getting help"},{"location":"gettinghelp/#getting-help","text":"You may encounter a problem when using guizero, so here are some ways you can get help to solve your problem.","title":"Getting help"},{"location":"gettinghelp/#getting-help_1","text":"If you have a question about your guizero program it is a good idea to join a community to ask for support: Raspberry Pi Forums - some people post questions about guizero on these forums and other members of the community step in to help. The creators of guizero periodically check the Python forum. Stack Overflow - a popular site for techy questions Computing at School - a useful site for teachers If you would like to read guides and resources for guizero there are many freely available: Getting started with GUIs - a beginners guide to guizero by the Raspberry Pi Foundation Python guizero video - a series of videos by Devon Schafer on using guizero. Example programs - some example programs to get you going. Using guizero with hardware - Ben Nuttall's projects using guizero combined with hardware Cat name generator - materials for a kids workshop, first run at the Cotswold Jam Name your pet - article on page 42 of Hello World magazine issue 2.","title":"Getting help"},{"location":"gettinghelp/#bugs-and-feature-requests","text":"Like many Python libraries, guizero has a GitHub repository where you can add issues. These issues come under two headings: You found a bug in guizero You would like to request we consider including a new feature We look at and respond to all issues created on GitHub. However, we ask that you only create issues for bugs and feature requests, rather than support, as we do not have time to answer everything :)","title":"Bugs and feature requests"},{"location":"images/","text":"Images Widgets such as Picture and PushButton allow you to use images in your GUI. from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() The types of image (GIF, JPG, PNG, etc) supported depend on how you installed guizero and the setup of your computer. Supported files types All systems support the GIF file type. Windows and Linux also support PNG files. If you installed the addition image features using pip it will also have installed PIL (Python Imaging Library) and you will be able use the majority of commonly used image types. guizero will tell you what file types are supported on your computer using the following code: from guizero import system_config print(system_config.supported_image_types) Operating System PIL NOT available PIL available Windows GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF MacOS GIF GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Linux GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Raspbian GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Resizing When the size of a widget is changed the image will be changed to fit the widget. If the additional image features were installed and PIL is available, the image will be scaled correctly, if not the image will be cropped. Animated GIFs If PIL is installed guizero supports displaying animated GIFs, if not, the GIF will be displayed as a static image.","title":"Images"},{"location":"images/#images","text":"Widgets such as Picture and PushButton allow you to use images in your GUI. from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() The types of image (GIF, JPG, PNG, etc) supported depend on how you installed guizero and the setup of your computer.","title":"Images"},{"location":"images/#supported-files-types","text":"All systems support the GIF file type. Windows and Linux also support PNG files. If you installed the addition image features using pip it will also have installed PIL (Python Imaging Library) and you will be able use the majority of commonly used image types. guizero will tell you what file types are supported on your computer using the following code: from guizero import system_config print(system_config.supported_image_types) Operating System PIL NOT available PIL available Windows GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF MacOS GIF GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Linux GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF Raspbian GIF, PNG GIF, Animated GIF, BMP, ICO, PNG, JPG, TIF","title":"Supported files types"},{"location":"images/#resizing","text":"When the size of a widget is changed the image will be changed to fit the widget. If the additional image features were installed and PIL is available, the image will be scaled correctly, if not the image will be cropped.","title":"Resizing"},{"location":"images/#animated-gifs","text":"If PIL is installed guizero supports displaying animated GIFs, if not, the GIF will be displayed as a static image.","title":"Animated GIFs"},{"location":"layout/","text":"Layouts The layout of your GUI is how you arrange the widgets in the window. Widgets can be arranged into \"containers\" (e.g. App , Window , Box ) using either of these layouts: auto - where widgets are positioned automatically grid - you specify where in a grid each widget should be positioned The layout is set using the layout parameter of the container, for example: app = App(layout=\"auto\") app = App(layout=\"grid\") If no layout parameter is specified, the default auto layout is used. Auto layout auto is the default layout used when a container is created. All widgets will be arranged in the order they are created and aligned to the centre. For example, the following code will create two Text widgets, one on top of the other. from guizero import App, Text app = App() text_1 = Text(app, text=\"on top\") text_2 = Text(app, text=\"below\") app.display() Aligning Widgets can be aligned to either the top , bottom , left or right , using the align property when created. Aligning a widget will cause it to be \"stuck\" to that side of the container, for example: from guizero import App, Text app = App() top_text = Text(app, text=\"at the top\", align=\"top\") bottom_text = Text(app, text=\"at the bottom\", align=\"bottom\") left_text = Text(app, text=\"to the left\", align=\"left\") right_text = Text(app, text=\"to the right\", align=\"right\") app.display() By aligning multiple widgets to the same side of the container, widgets can be made to stack together: from guizero import App, Text, TextBox, PushButton app = App() text = Text(app, text=\"label\", align=\"left\") text_box = TextBox(app, text=\"enter text\", align=\"left\") button = PushButton(app, text=\"submit\", align=\"left\") app.display() The widgets will stack in the order they are created, so the widget created first will be closest to the edge in the direction specified. Filling Widgets can also be made to \"fill\" all available space by setting the width and height parameters to fill . Here are some examples: A TextBox could span the entire width of the container: from guizero import App, TextBox app = App() text_box = TextBox(app, text=\"enter text\", width=\"fill\") app.display() Or a ListBox could fill the left hand side by using fill for the height and align to the left : from guizero import App, ListBox app = App() list_box = ListBox(app, items=[\"a list\"], height=\"fill\", align=\"left\") app.display() Using fill for the width and the height will make a widget use all of the available space: from guizero import App, PushButton app = App() button = PushButton(app, width=\"fill\", height=\"fill\") app.display() When multiple widgets use fill , the Window Manager (operating system) will distribute the space accordingly between all the widgets which have requested to fill it. from guizero import App, ListBox, PushButton app = App() list_box = ListBox(app, items=[\"a list\", \"of items\", \"yay\"], height=\"fill\", align=\"left\") button = PushButton(app, width=\"fill\", height=\"fill\", align=\"right\") app.display() Note : Using fill may not always have the effect you are expecting, as it is up to the operating system to distribute screen space. Grid layout The grid layout allows you to position widgets into a virtual grid. When you create a widget you will need to pass an extra parameter called grid which is a list containing [x,y] coordinates for where you want the widget to appear, like this: app = App(layout=\"grid\") text = Text(app, text=\"Hello world\", grid=[0,1]) There is no need to specify the width or height of the grid you want - it will expand depending on the coordinates you provide with each widget. However, grid cells containing no objects will have no height or width. This is really useful when creating GUIs where you want widgets to line up. For example, you could create a number keypad: from guizero import App, PushButton app = App(layout=\"grid\") button1 = PushButton(app, text=\"1\", grid=[0,0]) button2 = PushButton(app, text=\"2\", grid=[1,0]) button3 = PushButton(app, text=\"3\", grid=[2,0]) button4 = PushButton(app, text=\"4\", grid=[0,1]) button5 = PushButton(app, text=\"5\", grid=[1,1]) button6 = PushButton(app, text=\"6\", grid=[2,1]) button7 = PushButton(app, text=\"7\", grid=[0,2]) button8 = PushButton(app, text=\"8\", grid=[1,2]) button9 = PushButton(app, text=\"9\", grid=[2,2]) button0 = PushButton(app, text=\"0\", grid=[1,3]) app.display() You can also align widgets within the grid, which is useful when you are creating a form: from guizero import App, Text, TextBox app = App(layout=\"grid\") name_label = Text(app, text=\"Name\", grid=[0,0], align=\"left\") name = TextBox(app, grid=[1,0]) surname_label = Text(app, text=\"Surname\", grid=[0,1], align=\"left\") surname = TextBox(app, grid=[1,1]) dob_label = Text(app, text=\"Date of Birth\", grid=[0,2], align=\"left\") dob = TextBox(app, grid=[1,2]) app.display() Spanning columns or rows Widgets can be made to span multiple columns or rows by specifying the span within the grid parameter. These are optional, but if specified both must be included using the format [x,y,xspan,yspan] . The example below shows a Text widget located at 0,1 and spanning two columns (x) and one row (y): text = Text(app, text=\"Hello world\", grid=[0,1,2,1]) This layout method can be used to include widgets of different sizes arranged alongside each other. from guizero import App, Picture app = App(layout=\"grid\") picture1 = Picture(app, image=\"std1.gif\", grid=[0,0]) picture2 = Picture(app, image=\"std2.gif\", grid=[1,0]) picture3 = Picture(app, image=\"tall1.gif\", grid=[2,0,1,2]) picture4 = Picture(app, image=\"wide1.gif\", grid=[0,1,2,1]) app.display() Boxes By using a Box widget you can segment your GUI into different sections allowing you to lay out your user interface in any way you want. ( Code for example above ) If you wanted to create a title in the top left hand corner of your GUI, you could use a Box which fills the top of the App and put a Text widget inside aligned to the left . from guizero import App, Box, Text app = App() title_box = Box(app, width=\"fill\", align=\"top\") title = Text(title_box, text=\"title\", align=\"left\") app.display() You may find it easier to design your layout if your Boxes have borders, which can be done by setting the border parameter on Box to True . title_box = Box(app, width=\"fill\", align=\"top\", border=True) A similar method can be used to put \"OK\" and \"Cancel\" buttons at the bottom right of the GUI. Remember that the widgets will get stacked on the right in order of creation, so the cancel button is created first. from guizero import App, Box, PushButton app = App() buttons_box = Box(app, width=\"fill\", align=\"bottom\") cancel = PushButton(buttons_box, text=\"Cancel\", align=\"right\") ok = PushButton(buttons_box, text=\"OK\", align=\"right\") app.display() Note : You can put a Box inside another Box , allowing you to layer boxes and position your widgets. Tip : When creating a GUI you may find it easier to design it first on paper, noting where your boxes will be positioned. Unfortunately, whilst you can put one box inside another box, guizero does not support mailing it to yourself, nor smashing it with a hammer ;)","title":"Layouts"},{"location":"layout/#layouts","text":"The layout of your GUI is how you arrange the widgets in the window. Widgets can be arranged into \"containers\" (e.g. App , Window , Box ) using either of these layouts: auto - where widgets are positioned automatically grid - you specify where in a grid each widget should be positioned The layout is set using the layout parameter of the container, for example: app = App(layout=\"auto\") app = App(layout=\"grid\") If no layout parameter is specified, the default auto layout is used.","title":"Layouts"},{"location":"layout/#auto-layout","text":"auto is the default layout used when a container is created. All widgets will be arranged in the order they are created and aligned to the centre. For example, the following code will create two Text widgets, one on top of the other. from guizero import App, Text app = App() text_1 = Text(app, text=\"on top\") text_2 = Text(app, text=\"below\") app.display()","title":"Auto layout"},{"location":"layout/#aligning","text":"Widgets can be aligned to either the top , bottom , left or right , using the align property when created. Aligning a widget will cause it to be \"stuck\" to that side of the container, for example: from guizero import App, Text app = App() top_text = Text(app, text=\"at the top\", align=\"top\") bottom_text = Text(app, text=\"at the bottom\", align=\"bottom\") left_text = Text(app, text=\"to the left\", align=\"left\") right_text = Text(app, text=\"to the right\", align=\"right\") app.display() By aligning multiple widgets to the same side of the container, widgets can be made to stack together: from guizero import App, Text, TextBox, PushButton app = App() text = Text(app, text=\"label\", align=\"left\") text_box = TextBox(app, text=\"enter text\", align=\"left\") button = PushButton(app, text=\"submit\", align=\"left\") app.display() The widgets will stack in the order they are created, so the widget created first will be closest to the edge in the direction specified.","title":"Aligning"},{"location":"layout/#filling","text":"Widgets can also be made to \"fill\" all available space by setting the width and height parameters to fill . Here are some examples: A TextBox could span the entire width of the container: from guizero import App, TextBox app = App() text_box = TextBox(app, text=\"enter text\", width=\"fill\") app.display() Or a ListBox could fill the left hand side by using fill for the height and align to the left : from guizero import App, ListBox app = App() list_box = ListBox(app, items=[\"a list\"], height=\"fill\", align=\"left\") app.display() Using fill for the width and the height will make a widget use all of the available space: from guizero import App, PushButton app = App() button = PushButton(app, width=\"fill\", height=\"fill\") app.display() When multiple widgets use fill , the Window Manager (operating system) will distribute the space accordingly between all the widgets which have requested to fill it. from guizero import App, ListBox, PushButton app = App() list_box = ListBox(app, items=[\"a list\", \"of items\", \"yay\"], height=\"fill\", align=\"left\") button = PushButton(app, width=\"fill\", height=\"fill\", align=\"right\") app.display() Note : Using fill may not always have the effect you are expecting, as it is up to the operating system to distribute screen space.","title":"Filling"},{"location":"layout/#grid-layout","text":"The grid layout allows you to position widgets into a virtual grid. When you create a widget you will need to pass an extra parameter called grid which is a list containing [x,y] coordinates for where you want the widget to appear, like this: app = App(layout=\"grid\") text = Text(app, text=\"Hello world\", grid=[0,1]) There is no need to specify the width or height of the grid you want - it will expand depending on the coordinates you provide with each widget. However, grid cells containing no objects will have no height or width. This is really useful when creating GUIs where you want widgets to line up. For example, you could create a number keypad: from guizero import App, PushButton app = App(layout=\"grid\") button1 = PushButton(app, text=\"1\", grid=[0,0]) button2 = PushButton(app, text=\"2\", grid=[1,0]) button3 = PushButton(app, text=\"3\", grid=[2,0]) button4 = PushButton(app, text=\"4\", grid=[0,1]) button5 = PushButton(app, text=\"5\", grid=[1,1]) button6 = PushButton(app, text=\"6\", grid=[2,1]) button7 = PushButton(app, text=\"7\", grid=[0,2]) button8 = PushButton(app, text=\"8\", grid=[1,2]) button9 = PushButton(app, text=\"9\", grid=[2,2]) button0 = PushButton(app, text=\"0\", grid=[1,3]) app.display() You can also align widgets within the grid, which is useful when you are creating a form: from guizero import App, Text, TextBox app = App(layout=\"grid\") name_label = Text(app, text=\"Name\", grid=[0,0], align=\"left\") name = TextBox(app, grid=[1,0]) surname_label = Text(app, text=\"Surname\", grid=[0,1], align=\"left\") surname = TextBox(app, grid=[1,1]) dob_label = Text(app, text=\"Date of Birth\", grid=[0,2], align=\"left\") dob = TextBox(app, grid=[1,2]) app.display()","title":"Grid layout"},{"location":"layout/#spanning-columns-or-rows","text":"Widgets can be made to span multiple columns or rows by specifying the span within the grid parameter. These are optional, but if specified both must be included using the format [x,y,xspan,yspan] . The example below shows a Text widget located at 0,1 and spanning two columns (x) and one row (y): text = Text(app, text=\"Hello world\", grid=[0,1,2,1]) This layout method can be used to include widgets of different sizes arranged alongside each other. from guizero import App, Picture app = App(layout=\"grid\") picture1 = Picture(app, image=\"std1.gif\", grid=[0,0]) picture2 = Picture(app, image=\"std2.gif\", grid=[1,0]) picture3 = Picture(app, image=\"tall1.gif\", grid=[2,0,1,2]) picture4 = Picture(app, image=\"wide1.gif\", grid=[0,1,2,1]) app.display()","title":"Spanning columns or rows"},{"location":"layout/#boxes","text":"By using a Box widget you can segment your GUI into different sections allowing you to lay out your user interface in any way you want. ( Code for example above ) If you wanted to create a title in the top left hand corner of your GUI, you could use a Box which fills the top of the App and put a Text widget inside aligned to the left . from guizero import App, Box, Text app = App() title_box = Box(app, width=\"fill\", align=\"top\") title = Text(title_box, text=\"title\", align=\"left\") app.display() You may find it easier to design your layout if your Boxes have borders, which can be done by setting the border parameter on Box to True . title_box = Box(app, width=\"fill\", align=\"top\", border=True) A similar method can be used to put \"OK\" and \"Cancel\" buttons at the bottom right of the GUI. Remember that the widgets will get stacked on the right in order of creation, so the cancel button is created first. from guizero import App, Box, PushButton app = App() buttons_box = Box(app, width=\"fill\", align=\"bottom\") cancel = PushButton(buttons_box, text=\"Cancel\", align=\"right\") ok = PushButton(buttons_box, text=\"OK\", align=\"right\") app.display() Note : You can put a Box inside another Box , allowing you to layer boxes and position your widgets. Tip : When creating a GUI you may find it easier to design it first on paper, noting where your boxes will be positioned. Unfortunately, whilst you can put one box inside another box, guizero does not support mailing it to yourself, nor smashing it with a hammer ;)","title":"Boxes"},{"location":"listbox/","text":"ListBox __init__( self, master, items=None, selected=None, command=None, grid=None, align=None, visible=True, enabled=None, multiselect=False, scrollbar=False, width=None, height=None) What is it? The ListBox object displays a list of items from which either single or multiple items can be selected. How do I make one? Create a ListBox object like this: from guizero import App, ListBox app = App() listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display() Starting parameters When you create a ListBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) If you want the ListBox to allow multiple items to be selected you must set the multiselect optional parameter to True : listbox = ListBox(app, multiselect=True) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs selected string or List None No The item or items to select by default items List - Yes A list of items to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the ListBox will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiselect boolean False No If the widget should allow multiple items to be selected. scrollbar boolean False No If the widget should have a verticle scrollbar. width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" Methods You can call the following methods on a ListBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(item) item (string) - Appends a new item to the end of the ListBox. cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears all the items in a ListBox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, item) index (int), item (string) - Insert a new item in the ListBox at index remove(item) item (string) Boolean Removes the first item from the ListBox. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget children List A list of the widgets in this container. [ListBoxWidget, ListBoxScrollbar] enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" items List Returns a list of items in the ListBox master App or Box The container to which this widget belongs value string Sets or returns the items selected in a ListBox. Returns None if 0 items are selected. If the ListBox is a not multiselect , value is the item selected, if the ListBox is a multiselect , value is a list of items selected. visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Frame The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your ListBox object is called listbox you would write listbox.value . You can set the property (for example listbox.value = \"Chicken\" ) or get the value of the property to use (for example print(listbox.value) ). Examples Select a text color from a ListBox When an item in the ListBox is selected a function will be called to change the color of the text. from guizero import App, ListBox, Text def change_color(value): t.text_color = value a = App() t = Text(a, text=\"Its a ListBox\", color=\"black\") listbox = ListBox( a, items=[\"red\", \"green\", \"blue\", \"yellow\", \"purple\", \"turquoise\", \"pink\", \"orange\", \"black\", \"brown\", \"cyan\"], selected=\"black\", command=change_color, scrollbar=True) a.display() Using ListBox tk widgets Advanced users can gain internal access to the internal tkinter widgets used by ListBox . For more information on using tkinter in combination with guizero see Using tkinter . The ListBox widget contains a tkinter.Frame object, which frames 2 other child guizero widgets containing tkinter.Listbox and tkinter.Scrollbar objects. The .children property returns a list of these widgets: .children index guizero class tk class notes 0 ListBoxWidget tkinter.Listbox 1 ListBoxScrollbar tkinter.Scrollbar A ListBoxScrollbar widget will only be present if ListBox.scrollbar is set to True . To access the internal tk object for these child guizero widgets you would use its tk property e.g. listbox = listBox(app) tk_listbox = listbox.children[0].tk tk_scrollbar = listbox.children[1].tk","title":"ListBox"},{"location":"listbox/#listbox","text":"__init__( self, master, items=None, selected=None, command=None, grid=None, align=None, visible=True, enabled=None, multiselect=False, scrollbar=False, width=None, height=None)","title":"ListBox"},{"location":"listbox/#what-is-it","text":"The ListBox object displays a list of items from which either single or multiple items can be selected.","title":"What is it?"},{"location":"listbox/#how-do-i-make-one","text":"Create a ListBox object like this: from guizero import App, ListBox app = App() listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) app.display()","title":"How do I make one?"},{"location":"listbox/#starting-parameters","text":"When you create a ListBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: listbox = ListBox(app, items=[\"Beef\", \"Chicken\", \"Fish\", \"Vegetarian\"]) If you want the ListBox to allow multiple items to be selected you must set the multiselect optional parameter to True : listbox = ListBox(app, multiselect=True) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs selected string or List None No The item or items to select by default items List - Yes A list of items to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when a different option is selected. This function MUST take either zero or one argument, if the function takes one argument the current value of the ListBox will be given. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiselect boolean False No If the widget should allow multiple items to be selected. scrollbar boolean False No If the widget should have a verticle scrollbar. width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\"","title":"Starting parameters"},{"location":"listbox/#methods","text":"You can call the following methods on a ListBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(item) item (string) - Appends a new item to the end of the ListBox. cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears all the items in a ListBox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. insert(index, item) index (int), item (string) - Insert a new item in the ListBox at index remove(item) item (string) Boolean Removes the first item from the ListBox. Returns True if an item was removed. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when a different option is selected.","title":"Methods"},{"location":"listbox/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget children List A list of the widgets in this container. [ListBoxWidget, ListBoxScrollbar] enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" items List Returns a list of items in the ListBox master App or Box The container to which this widget belongs value string Sets or returns the items selected in a ListBox. Returns None if 0 items are selected. If the ListBox is a not multiselect , value is the item selected, if the ListBox is a multiselect , value is a list of items selected. visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Frame The internal tkinter object, see Using tkinter Refer to a property as .property . For example, if your ListBox object is called listbox you would write listbox.value . You can set the property (for example listbox.value = \"Chicken\" ) or get the value of the property to use (for example print(listbox.value) ).","title":"Properties"},{"location":"listbox/#examples","text":"Select a text color from a ListBox When an item in the ListBox is selected a function will be called to change the color of the text. from guizero import App, ListBox, Text def change_color(value): t.text_color = value a = App() t = Text(a, text=\"Its a ListBox\", color=\"black\") listbox = ListBox( a, items=[\"red\", \"green\", \"blue\", \"yellow\", \"purple\", \"turquoise\", \"pink\", \"orange\", \"black\", \"brown\", \"cyan\"], selected=\"black\", command=change_color, scrollbar=True) a.display()","title":"Examples"},{"location":"listbox/#using-listbox-tk-widgets","text":"Advanced users can gain internal access to the internal tkinter widgets used by ListBox . For more information on using tkinter in combination with guizero see Using tkinter . The ListBox widget contains a tkinter.Frame object, which frames 2 other child guizero widgets containing tkinter.Listbox and tkinter.Scrollbar objects. The .children property returns a list of these widgets: .children index guizero class tk class notes 0 ListBoxWidget tkinter.Listbox 1 ListBoxScrollbar tkinter.Scrollbar A ListBoxScrollbar widget will only be present if ListBox.scrollbar is set to True . To access the internal tk object for these child guizero widgets you would use its tk property e.g. listbox = listBox(app) tk_listbox = listbox.children[0].tk tk_scrollbar = listbox.children[1].tk","title":"Using ListBox tk widgets"},{"location":"menubar/","text":"MenuBar __init__( self, master, toplevel, options) What is it? The MenuBar object displays a menu at the top of the screen, with each menu option leading to a submenu. How do I make one? Create a MenuBar object like this: from guizero import App, MenuBar def file_function(): print(\"File option\") def edit_function(): print(\"Edit option\") app = App() menubar = MenuBar(app, toplevel=[\"File\", \"Edit\"], options=[ [ [\"File option 1\", file_function], [\"File option 2\", file_function] ], [ [\"Edit option 1\", edit_function], [\"Edit option 2\", edit_function] ] ]) app.display() Starting parameters When you create a MenuBar object you must specify all of the parameters. Parameter Takes Default Compulsory Description master App - Yes The container to which this widget belongs toplevel list - Yes A list of top level menu items options 3D list - Yes A list of submenus, with each submenu being a list of options and each option being a text/command pair. See notes above for more details. The toplevel parameter should be a list of options you wish to display on the menu. In the example, the toplevel options are File and Edit: The options parameter should be a 3D List containing lists of submenu items, which are themselves lists. The elements in the list correspond to the elements in the toplevel list, so the first list of submenu items provided in options will be the submenu for the first menu heading provided in toplevel and so on. The menu item sub-sublists within options should contain pairs consisting of the text to display on the menu and the function to call when that option is selected. In this example, the text \"File option 1\" is displayed and the function file_function is called if this option is clicked on. [\"File option 1\", file_function] The MenuBar is never displayed on a grid so there are no grid or alignment parameters. Methods You can call the following methods on an MenuBar object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. Properties You can set and get the following properties: Method Data type Description master App The App object to which this MenuBar belongs tk tkinter.Menu The internal tkinter object, see Using tkinter","title":"MenuBar"},{"location":"menubar/#menubar","text":"__init__( self, master, toplevel, options)","title":"MenuBar"},{"location":"menubar/#what-is-it","text":"The MenuBar object displays a menu at the top of the screen, with each menu option leading to a submenu.","title":"What is it?"},{"location":"menubar/#how-do-i-make-one","text":"Create a MenuBar object like this: from guizero import App, MenuBar def file_function(): print(\"File option\") def edit_function(): print(\"Edit option\") app = App() menubar = MenuBar(app, toplevel=[\"File\", \"Edit\"], options=[ [ [\"File option 1\", file_function], [\"File option 2\", file_function] ], [ [\"Edit option 1\", edit_function], [\"Edit option 2\", edit_function] ] ]) app.display()","title":"How do I make one?"},{"location":"menubar/#starting-parameters","text":"When you create a MenuBar object you must specify all of the parameters. Parameter Takes Default Compulsory Description master App - Yes The container to which this widget belongs toplevel list - Yes A list of top level menu items options 3D list - Yes A list of submenus, with each submenu being a list of options and each option being a text/command pair. See notes above for more details. The toplevel parameter should be a list of options you wish to display on the menu. In the example, the toplevel options are File and Edit: The options parameter should be a 3D List containing lists of submenu items, which are themselves lists. The elements in the list correspond to the elements in the toplevel list, so the first list of submenu items provided in options will be the submenu for the first menu heading provided in toplevel and so on. The menu item sub-sublists within options should contain pairs consisting of the text to display on the menu and the function to call when that option is selected. In this example, the text \"File option 1\" is displayed and the function file_function is called if this option is clicked on. [\"File option 1\", file_function] The MenuBar is never displayed on a grid so there are no grid or alignment parameters.","title":"Starting parameters"},{"location":"menubar/#methods","text":"You can call the following methods on an MenuBar object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor.","title":"Methods"},{"location":"menubar/#properties","text":"You can set and get the following properties: Method Data type Description master App The App object to which this MenuBar belongs tk tkinter.Menu The internal tkinter object, see Using tkinter","title":"Properties"},{"location":"multiple_windows/","text":"Multiple Windows A guizero application should only have have one single App object - this is the main window and controller of your program. If you want to create a second (or 3rd, 4th, 5th) window, your program should use a Window object. A Second window When you create a second Window you need to pass it the App , just like when you create a widget: from guizero import App, Window app = App(title=\"Main window\") window = Window(app, title=\"Second window\") app.display() Adding widgets to the second window is the same as adding them to an App . You tell the widget which window it will be in by passing it the name of the Window : from guizero import App, Window, Text app = App(title=\"Main window\") window = Window(app, title=\"Second window\") text = Text(window, text=\"This text will show up in the second window\") app.display() Opening and closing windows When a Window object is created it is immediately displayed on the screen. You can control whether a window is visible or not using the show() and hide() methods. This code creates a window which is shown when a button on the App is clicked and closed when a button is clicked in the Window . from guizero import App, Window, PushButton def open_window(): window.show() def close_window(): window.hide() app = App(title=\"Main window\") window = Window(app, title=\"Second window\") window.hide() open_button = PushButton(app, text=\"Open\", command=open_window) close_button = PushButton(window, text=\"Close\", command=close_window) app.display() Modal windows When a window is opened using show() it opens side by side with the main window, and both windows can be used at the same time. A \"modal\" window prevents the other windows in the application being used until it is closed. To create a modal window, you can pass True to the optional wait parameter of show . This will force all other windows to wait until this window is closed before they can be used. def open_window(): window.show(wait=True)","title":"Multiple windows"},{"location":"multiple_windows/#multiple-windows","text":"A guizero application should only have have one single App object - this is the main window and controller of your program. If you want to create a second (or 3rd, 4th, 5th) window, your program should use a Window object.","title":"Multiple Windows"},{"location":"multiple_windows/#a-second-window","text":"When you create a second Window you need to pass it the App , just like when you create a widget: from guizero import App, Window app = App(title=\"Main window\") window = Window(app, title=\"Second window\") app.display() Adding widgets to the second window is the same as adding them to an App . You tell the widget which window it will be in by passing it the name of the Window : from guizero import App, Window, Text app = App(title=\"Main window\") window = Window(app, title=\"Second window\") text = Text(window, text=\"This text will show up in the second window\") app.display()","title":"A Second window"},{"location":"multiple_windows/#opening-and-closing-windows","text":"When a Window object is created it is immediately displayed on the screen. You can control whether a window is visible or not using the show() and hide() methods. This code creates a window which is shown when a button on the App is clicked and closed when a button is clicked in the Window . from guizero import App, Window, PushButton def open_window(): window.show() def close_window(): window.hide() app = App(title=\"Main window\") window = Window(app, title=\"Second window\") window.hide() open_button = PushButton(app, text=\"Open\", command=open_window) close_button = PushButton(window, text=\"Close\", command=close_window) app.display()","title":"Opening and closing windows"},{"location":"multiple_windows/#modal-windows","text":"When a window is opened using show() it opens side by side with the main window, and both windows can be used at the same time. A \"modal\" window prevents the other windows in the application being used until it is closed. To create a modal window, you can pass True to the optional wait parameter of show . This will force all other windows to wait until this window is closed before they can be used. def open_window(): window.show(wait=True)","title":"Modal windows"},{"location":"picture/","text":"Picture __init__( self, master, image=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Picture object displays an image. How do I make one? Create a Picture object like this: from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() You must specify the correct path to the image. The image in the example is in the same directory as the program. If the image is in a different directory, specify a relative path, for example if the picture is in a subfolder called images you would write: picture = Picture(app, image=\"images/test.gif\") Image support Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use with Picture . By default GIF and PNG are supported, except macOS which only supports GIF. Starting parameters When you create a Picture object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: picture = Picture(app, image=\"test.gif\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels height size None No Set the height of the widget in pixels Methods You can call the following methods on a Picture object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels image string The file path, tkinter.PhotoImage or PIL.Image you wish to display master App or Box The container to which this widget belongs tk tkinter.Label The internal tkinter object, see Using tkinter value string The file path, tkinter.PhotoImage or PIL.Image you wish to display visible boolean If this widget is visible width size Set the width of the widget in pixels Refer to a property as .property . For example, if your Picture object is called picture you would write picture.value . You can set the property (for example picture.value = \"star.gif\" ) or get the value of the property to use (for example print(picture.value) ).","title":"Picture"},{"location":"picture/#picture","text":"__init__( self, master, image=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Picture"},{"location":"picture/#what-is-it","text":"The Picture object displays an image.","title":"What is it?"},{"location":"picture/#how-do-i-make-one","text":"Create a Picture object like this: from guizero import App, Picture app = App() picture = Picture(app, image=\"test.gif\") app.display() You must specify the correct path to the image. The image in the example is in the same directory as the program. If the image is in a different directory, specify a relative path, for example if the picture is in a subfolder called images you would write: picture = Picture(app, image=\"images/test.gif\")","title":"How do I make one?"},{"location":"picture/#image-support","text":"Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use with Picture . By default GIF and PNG are supported, except macOS which only supports GIF.","title":"Image support"},{"location":"picture/#starting-parameters","text":"When you create a Picture object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: picture = Picture(app, image=\"test.gif\") Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels height size None No Set the height of the widget in pixels","title":"Starting parameters"},{"location":"picture/#methods","text":"You can call the following methods on a Picture object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden","title":"Methods"},{"location":"picture/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels image string The file path, tkinter.PhotoImage or PIL.Image you wish to display master App or Box The container to which this widget belongs tk tkinter.Label The internal tkinter object, see Using tkinter value string The file path, tkinter.PhotoImage or PIL.Image you wish to display visible boolean If this widget is visible width size Set the width of the widget in pixels Refer to a property as .property . For example, if your Picture object is called picture you would write picture.value . You can set the property (for example picture.value = \"star.gif\" ) or get the value of the property to use (for example print(picture.value) ).","title":"Properties"},{"location":"pushbutton/","text":"PushButton __init__( self, master, command=None, args=None, text=\"Button\", image=None, pady=10, padx=10, grid=None, align=None, icon=None, visible=True, enabled=None, width=None, height=None) What is it? The PushButton object displays a button with text or an image, which calls a function when pressed. How do I make one? Create a PushButton object like this: from guizero import App, PushButton def do_nothing(): print(\"Button was pressed\") app = App() button = PushButton(app, command=do_nothing) app.display() Create a picture PushButton with an image like this: from guizero import App, PushButton def do_nothing(): print(\"A picture button was pressed\") app = App() button = PushButton(app, image=\"button.gif\", command=do_nothing) app.display() Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use for PushButton . By default GIF and PNG are supported, except macOS which only supports GIF. Starting parameters When you create a PushButton object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: button = PushButton(app) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs command function name None - The name of a function to call when the button is pressed. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display. If both an image and text are specified, the image will override the text. padx int 10 - How much horizontal padding to add between the text/icon and the edge of the button. pady int 10 - How much vertical padding to add between the text/icon and the edge of the button. text string \"Button\" - The text to display on the button visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or pixels if its an image button or to \"fill\" height size None No Set the height of the widget in characters or pixels if its an image button or to \"fill\" Methods You can call the following methods on a PushButton object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(image_source) image_source (string) - The file path, tkinter.PhotoImage or PIL.Image you wish to display. padding(padx, pady) padx (int), pady(int) - Sets the amount of x (horizontal) and y (vertical) padding between the text/icon and the edge of the button repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Changes the state of the button to the opposite of its current state - if it is currently enabled, disable it and vice versa. update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the button is pressed . Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text on the button grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or pixels if its an image button or to \"fill\" master App or Box The container to which this widget belongs text string The text on the button text_color color The colour of the text on the button text_size int The size of the text on the button tk tkinter.Button The internal tkinter object, see Using tkinter value int Returns 1 when the button is pressed, 0 if the button is released visible boolean If this widget is visible width size Set the width of the widget in characters or pixels if its an image button or to \"fill\" Refer to a property as .property . For example, if your PushButton object is called button you would write button.value . You can set the property (for example button.bg = \"red\" ) or get the value of the property to use (for example print(button.bg) ).","title":"PushButton"},{"location":"pushbutton/#pushbutton","text":"__init__( self, master, command=None, args=None, text=\"Button\", image=None, pady=10, padx=10, grid=None, align=None, icon=None, visible=True, enabled=None, width=None, height=None)","title":"PushButton"},{"location":"pushbutton/#what-is-it","text":"The PushButton object displays a button with text or an image, which calls a function when pressed.","title":"What is it?"},{"location":"pushbutton/#how-do-i-make-one","text":"Create a PushButton object like this: from guizero import App, PushButton def do_nothing(): print(\"Button was pressed\") app = App() button = PushButton(app, command=do_nothing) app.display() Create a picture PushButton with an image like this: from guizero import App, PushButton def do_nothing(): print(\"A picture button was pressed\") app = App() button = PushButton(app, image=\"button.gif\", command=do_nothing) app.display() Depending on your operating system and whether you installed the guizero additional image features will determine what image types you can use for PushButton . By default GIF and PNG are supported, except macOS which only supports GIF.","title":"How do I make one?"},{"location":"pushbutton/#starting-parameters","text":"When you create a PushButton object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: button = PushButton(app) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs command function name None - The name of a function to call when the button is pressed. align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . args list None - If you wish to pass any arguments to the function specified in the command parameter, you can specify them as a list grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. image string None - The file path, tkinter.PhotoImage or PIL.Image you wish to display. If both an image and text are specified, the image will override the text. padx int 10 - How much horizontal padding to add between the text/icon and the edge of the button. pady int 10 - How much vertical padding to add between the text/icon and the edge of the button. text string \"Button\" - The text to display on the button visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or pixels if its an image button or to \"fill\" height size None No Set the height of the widget in characters or pixels if its an image button or to \"fill\"","title":"Starting parameters"},{"location":"pushbutton/#methods","text":"You can call the following methods on a PushButton object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. image(image_source) image_source (string) - The file path, tkinter.PhotoImage or PIL.Image you wish to display. padding(padx, pady) padx (int), pady(int) - Sets the amount of x (horizontal) and y (vertical) padding between the text/icon and the edge of the button repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden toggle() - - Changes the state of the button to the opposite of its current state - if it is currently enabled, disable it and vice versa. update_command(command, args =None) command (function name), args ( Optional List of arguments to be passed to command) - Updates the function to call when the button is pressed .","title":"Methods"},{"location":"pushbutton/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text on the button grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or pixels if its an image button or to \"fill\" master App or Box The container to which this widget belongs text string The text on the button text_color color The colour of the text on the button text_size int The size of the text on the button tk tkinter.Button The internal tkinter object, see Using tkinter value int Returns 1 when the button is pressed, 0 if the button is released visible boolean If this widget is visible width size Set the width of the widget in characters or pixels if its an image button or to \"fill\" Refer to a property as .property . For example, if your PushButton object is called button you would write button.value . You can set the property (for example button.bg = \"red\" ) or get the value of the property to use (for example print(button.bg) ).","title":"Properties"},{"location":"recipes/","text":"Recipes These are examples of how you can use guizero to create user interfaces. Don't be restricted to these ideas, check out Using guizero and the widgets . Hello World Create a guizero app and display some text. from guizero import App, Text app = App() text = Text(app, text=\"hello world\") app.display() Get some text Get some data from the user using a TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Enter your name\") app.display() Push a button Use a PushButton to display a message when the button is pressed. from guizero import App, TextBox, PushButton, Text def update_text(): label.value = name.value app = App() label = Text(app, text=\"What's your name?\") name = TextBox(app) button = PushButton(app, command=update_text) app.display() Display an image Use a Picture object to display an image. from guizero import App, Picture app = App() pic = Picture(app, image=\"myimage.gif\") app.display() Toggle 2 buttons Have 2 buttons, start and stop with them changing the enabled state of each other. from guizero import App, PushButton def start(): start_button.disable() stop_button.enable() def stop(): start_button.enable() stop_button.disable() app = App() start_button = PushButton(app, command=start, text=\"start\") stop_button = PushButton(app, command=stop, text=\"stop\", enabled=False) app.display() Change your apps appearance Your app doesn't have to use the standard colors and text, let your user pick the background and text color from 2 combo's. from guizero import App, Combo, Text def update_bg(): app.bg = bg_combo.value def update_text(): app.text_color = text_combo.value colors = [\"black\", \"white\", \"red\", \"green\", \"blue\"] app = App() app.bg = \"black\" app.text_color = \"white\" title1 = Text(app, text=\"Background color\") bg_combo = Combo(app, options=colors, selected=app.bg, command=update_bg) title2 = Text(app, text=\"Text color\") text_combo = Combo(app, options=colors, selected=app.text_color, command=update_text) app.display() Scale an image Display an image on the screen with 2 sliders, 1 for height and 1 for width. from guizero import App, Slider, Picture def resize(): picture.width = width.value picture.height = height.value app = App(layout=\"grid\") picture = Picture(app, image=\"image.gif\", grid=[0,1]) width = Slider(app, command=resize, grid=[0,0], start=1, end=picture.width) width.width = picture.width width.value = picture.width height = Slider(app, command=resize, horizontal=False, grid=[1,1], start=1, end=picture.height) height.height = picture.height height.value = picture.height app.display()","title":"Recipes"},{"location":"recipes/#recipes","text":"These are examples of how you can use guizero to create user interfaces. Don't be restricted to these ideas, check out Using guizero and the widgets .","title":"Recipes"},{"location":"recipes/#hello-world","text":"Create a guizero app and display some text. from guizero import App, Text app = App() text = Text(app, text=\"hello world\") app.display()","title":"Hello World"},{"location":"recipes/#get-some-text","text":"Get some data from the user using a TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Enter your name\") app.display()","title":"Get some text"},{"location":"recipes/#push-a-button","text":"Use a PushButton to display a message when the button is pressed. from guizero import App, TextBox, PushButton, Text def update_text(): label.value = name.value app = App() label = Text(app, text=\"What's your name?\") name = TextBox(app) button = PushButton(app, command=update_text) app.display()","title":"Push a button"},{"location":"recipes/#display-an-image","text":"Use a Picture object to display an image. from guizero import App, Picture app = App() pic = Picture(app, image=\"myimage.gif\") app.display()","title":"Display an image"},{"location":"recipes/#toggle-2-buttons","text":"Have 2 buttons, start and stop with them changing the enabled state of each other. from guizero import App, PushButton def start(): start_button.disable() stop_button.enable() def stop(): start_button.enable() stop_button.disable() app = App() start_button = PushButton(app, command=start, text=\"start\") stop_button = PushButton(app, command=stop, text=\"stop\", enabled=False) app.display()","title":"Toggle 2 buttons"},{"location":"recipes/#change-your-apps-appearance","text":"Your app doesn't have to use the standard colors and text, let your user pick the background and text color from 2 combo's. from guizero import App, Combo, Text def update_bg(): app.bg = bg_combo.value def update_text(): app.text_color = text_combo.value colors = [\"black\", \"white\", \"red\", \"green\", \"blue\"] app = App() app.bg = \"black\" app.text_color = \"white\" title1 = Text(app, text=\"Background color\") bg_combo = Combo(app, options=colors, selected=app.bg, command=update_bg) title2 = Text(app, text=\"Text color\") text_combo = Combo(app, options=colors, selected=app.text_color, command=update_text) app.display()","title":"Change your apps appearance"},{"location":"recipes/#scale-an-image","text":"Display an image on the screen with 2 sliders, 1 for height and 1 for width. from guizero import App, Slider, Picture def resize(): picture.width = width.value picture.height = height.value app = App(layout=\"grid\") picture = Picture(app, image=\"image.gif\", grid=[0,1]) width = Slider(app, command=resize, grid=[0,0], start=1, end=picture.width) width.width = picture.width width.value = picture.width height = Slider(app, command=resize, horizontal=False, grid=[1,1], start=1, end=picture.height) height.height = picture.height height.value = picture.height app.display()","title":"Scale an image"},{"location":"size/","text":"Sizes You can set the width and height of widgets in guizero. Widgets are sized by either pixels or characters depending on the widget and what it contains. Some widgets size can also be set to \"fill\" where it will use up all of the available space. from guizero import App, PushButton, Slider, ListBox app = App() # A PushButton's size is noted in characters button = PushButton(app, width=30, height=5) # A Slider's size is noted in pixels slider = Slider(app, width=300, height=30) # Some widgets such as ListBox can also be told to fill all the available space listbox = ListBox(app, width=\"fill\", height=\"fill\") app.display() Widget Characters or Pixels Fill Notes Box Pixels Yes If a Box is sized in Pixels, both width and height must be specified. ButtonGroup Characters Yes The height of a ButtonGroup must divide by the number of buttons in it CheckBox Characters Yes Combo Characters Yes ListBox Pixels Yes Picture Pixels No See Images for more information PushButton Characters Yes PushButton with image Pixels No PushButton's which have images are sized in pixels Slider Pixels Yes Text Characters Yes TextBox Characters Yes Only a TextBox's width can be set Waffle Pixels No","title":"Sizes"},{"location":"size/#sizes","text":"You can set the width and height of widgets in guizero. Widgets are sized by either pixels or characters depending on the widget and what it contains. Some widgets size can also be set to \"fill\" where it will use up all of the available space. from guizero import App, PushButton, Slider, ListBox app = App() # A PushButton's size is noted in characters button = PushButton(app, width=30, height=5) # A Slider's size is noted in pixels slider = Slider(app, width=300, height=30) # Some widgets such as ListBox can also be told to fill all the available space listbox = ListBox(app, width=\"fill\", height=\"fill\") app.display() Widget Characters or Pixels Fill Notes Box Pixels Yes If a Box is sized in Pixels, both width and height must be specified. ButtonGroup Characters Yes The height of a ButtonGroup must divide by the number of buttons in it CheckBox Characters Yes Combo Characters Yes ListBox Pixels Yes Picture Pixels No See Images for more information PushButton Characters Yes PushButton with image Pixels No PushButton's which have images are sized in pixels Slider Pixels Yes Text Characters Yes TextBox Characters Yes Only a TextBox's width can be set Waffle Pixels No","title":"Sizes"},{"location":"slider/","text":"Slider __init__( self, master, start=0, end=100, horizontal=True, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Slider object displays a bar and selector which can be used to specify a value in a range. The above code looks like this on Windows: How do I make one? Create a Slider object like this: from guizero import App, Slider app = App() slider = Slider(app) app.display() Starting paramters When you create a Slider object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: slider = Slider(app, horizontal=False) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the slider value is changed end int 100 - The largest value selectable on the slider grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal Boolean True - Whether you wish to display your slider horizontally or vertically (defaults to horizontal) start int 0 - The smallest value selectable on the slider visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\" Methods You can call the following methods on a Slider object. Method Takes Returns Description the function specified in command after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the slider value is changed Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text tk tkinter.Scale The internal tkinter object, see Using tkinter value string The current value of the slider visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\" Examples Calling a function when the slider value changes You can specify a function to call when the slider value changes. Your function MUST have a minimum of one parameter as it will automatically receive a string containing the value of the slider (called slider_value in the example) when it is called. This code has a slider and a text box, and the text box updates automatically to display the current value of the slider. from guizero import App, Slider, TextBox def slider_changed(slider_value): textbox.value = slider_value app = App() slider = Slider(app, command=slider_changed) textbox = TextBox(app) app.display()","title":"Slider"},{"location":"slider/#slider","text":"__init__( self, master, start=0, end=100, horizontal=True, command=None, grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Slider"},{"location":"slider/#what-is-it","text":"The Slider object displays a bar and selector which can be used to specify a value in a range. The above code looks like this on Windows:","title":"What is it?"},{"location":"slider/#how-do-i-make-one","text":"Create a Slider object like this: from guizero import App, Slider app = App() slider = Slider(app) app.display()","title":"How do I make one?"},{"location":"slider/#starting-paramters","text":"When you create a Slider object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: slider = Slider(app, horizontal=False) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . command function name None - The name of a function to call when the slider value is changed end int 100 - The largest value selectable on the slider grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. horizontal Boolean True - Whether you wish to display your slider horizontally or vertically (defaults to horizontal) start int 0 - The smallest value selectable on the slider visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in pixels or to \"fill\" height size None No Set the height of the widget in pixels or to \"fill\"","title":"Starting paramters"},{"location":"slider/#methods","text":"You can call the following methods on a Slider object. Method Takes Returns Description the function specified in command after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the slider value is changed","title":"Methods"},{"location":"slider/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in pixels or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text tk tkinter.Scale The internal tkinter object, see Using tkinter value string The current value of the slider visible boolean If this widget is visible width size Set the width of the widget in pixels or to \"fill\"","title":"Properties"},{"location":"slider/#examples","text":"Calling a function when the slider value changes You can specify a function to call when the slider value changes. Your function MUST have a minimum of one parameter as it will automatically receive a string containing the value of the slider (called slider_value in the example) when it is called. This code has a slider and a text box, and the text box updates automatically to display the current value of the slider. from guizero import App, Slider, TextBox def slider_changed(slider_value): textbox.value = slider_value app = App() slider = Slider(app, command=slider_changed) textbox = TextBox(app) app.display()","title":"Examples"},{"location":"start/","text":"Getting Started At the start of every guizero program, choose the widgets you need from the guizero library and import them: from guizero import App, PushButton, Slider You only need to import each widget once, and then you can use it in your program as many times as you like. Hello World All guizero projects begin with a main window which is called an App . At the end of every guizero program you must tell the program to display the app you have just created. Let's create an app window with the title \"Hello world\": from guizero import App app = App(title=\"Hello world\") app.display() Save and run the code - you've created your first guizero app! Adding widgets Widgets are the things which appear on the GUI, such as text boxes, buttons, sliders and even plain old pieces of text. All widgets go between the line of code to create the App and the app.display() line. from guizero import App, Text app = App(title=\"Hello world\") message = Text(app, text=\"Welcome to the Hello world app!\") app.display() Let\u2019s look at the Text widget code in a bit more detail: message = Text(app, text=\"Welcome to the Hello world app!\") message = - The Text object has a name, just like any variable Text - an object which creates a piece of text on the screen app \u2013 This tells the Text where it will live. Most of the time your widgets will live directly inside the app. text=\"Welcome to the Hello world app!\" - The text to display And that's it! Now have a look on the documentation pages for the individual widgets to find out more about how to use them.","title":"Getting started"},{"location":"start/#getting-started","text":"At the start of every guizero program, choose the widgets you need from the guizero library and import them: from guizero import App, PushButton, Slider You only need to import each widget once, and then you can use it in your program as many times as you like.","title":"Getting Started"},{"location":"start/#hello-world","text":"All guizero projects begin with a main window which is called an App . At the end of every guizero program you must tell the program to display the app you have just created. Let's create an app window with the title \"Hello world\": from guizero import App app = App(title=\"Hello world\") app.display() Save and run the code - you've created your first guizero app!","title":"Hello World"},{"location":"start/#adding-widgets","text":"Widgets are the things which appear on the GUI, such as text boxes, buttons, sliders and even plain old pieces of text. All widgets go between the line of code to create the App and the app.display() line. from guizero import App, Text app = App(title=\"Hello world\") message = Text(app, text=\"Welcome to the Hello world app!\") app.display() Let\u2019s look at the Text widget code in a bit more detail: message = Text(app, text=\"Welcome to the Hello world app!\") message = - The Text object has a name, just like any variable Text - an object which creates a piece of text on the screen app \u2013 This tells the Text where it will live. Most of the time your widgets will live directly inside the app. text=\"Welcome to the Hello world app!\" - The text to display And that's it! Now have a look on the documentation pages for the individual widgets to find out more about how to use them.","title":"Adding widgets"},{"location":"text/","text":"Text __init__( self, master, text=\"\", size=12, color=\"black\", bg=None, font=\"Helvetica\", grid=None, align=None, visible=True, enabled=None, width=None, height=None) What is it? The Text object displays non editable text in your app, useful for titles, labels and instructions. How do I make one? Create a Text object like this: from guizero import App, Text app = App() text = Text(app, text=\"Hello World\") app.display() Starting parameters When you create a Text object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: text = Text(app, text=\"hi\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color black - The colour of the text. Accepts some colour strings (e.g. red ) and colours specified in hex format (e.g. #0099ff ) font string \"Helvetica\" - The font face that the text will be displayed in. Availability of fonts depends on which fonts are installed locally. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. size int 12 - The font size of the text text string \"\" - The text you want to display visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\" Methods You can call the following methods on a Text object.. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the object cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the text destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text tk tkinter.Label The internal tkinter object, see Using tkinter value string The text visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\"","title":"Text"},{"location":"text/#text","text":"__init__( self, master, text=\"\", size=12, color=\"black\", bg=None, font=\"Helvetica\", grid=None, align=None, visible=True, enabled=None, width=None, height=None)","title":"Text"},{"location":"text/#what-is-it","text":"The Text object displays non editable text in your app, useful for titles, labels and instructions.","title":"What is it?"},{"location":"text/#how-do-i-make-one","text":"Create a Text object like this: from guizero import App, Text app = App() text = Text(app, text=\"Hello World\") app.display()","title":"How do I make one?"},{"location":"text/#starting-parameters","text":"When you create a Text object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: text = Text(app, text=\"hi\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color black - The colour of the text. Accepts some colour strings (e.g. red ) and colours specified in hex format (e.g. #0099ff ) font string \"Helvetica\" - The font face that the text will be displayed in. Availability of fonts depends on which fonts are installed locally. grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. size int 12 - The font size of the text text string \"\" - The text you want to display visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master width size None No Set the width of the widget in characters or to \"fill\" height size None No Set the height of the widget in characters or to \"fill\"","title":"Starting parameters"},{"location":"text/#methods","text":"You can call the following methods on a Text object.. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the object cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the text destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden","title":"Methods"},{"location":"text/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" master App or Box The container to which this widget belongs text_size int The size of the text text_color color The colour of the text tk tkinter.Label The internal tkinter object, see Using tkinter value string The text visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\"","title":"Properties"},{"location":"textbox/","text":"TextBox __init__( self, master, text=\"\", width=10, height=1, grid=None, align=None, visible=True, enabled=None, multiline=False, scrollbar=False, command=None, hide_text=False) What is it The TextBox object displays a text box which the user can type in. How do I make one? Create a TextBox object like this: from guizero import App, TextBox app = App() input_box = TextBox(app) app.display() Starting parameters When you create a TextBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: textbox = TextBox(app, text=\"Please enter some text\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. text string \"\" - Any text you wish to be pre-filled in the text box width int 10 - Set the width of the widget in characters or to \"fill\" height int 1 - Set the height of the widget in characters or to \"fill\" , only effective if multiline is True visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiline boolean False No Create a multi-line text box. scrollbar boolean False No Add a vertical scrollbar to a multi-line text box command function name None - The name of a function to call when the text is changed. This function MUST take either zero or one argument, if the function takes one argument the key which was added to the textbox will be returned. hide_text boolean False - When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character. Methods You can call the following methods on your TextBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the text box cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the textbox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the text is changed. Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" , only effective if multiline is True hide_text boolean / char When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character. master App or Box The container to which this widget belongs value string The text in the TextBox visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Entry The internal tkinter object, see Using tkinter Examples Creating a TextBox with default text You can set the default text in a TextBox when it is created using the text parameter: from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type here\") app.display() Creating a password TextBox with hidden text You can hide the text in a TextBox using the hide_text parameter: from guizero import App, TextBox app = App() password_box = TextBox(app, hide_text=True) app.display() Creating a multi-line TextBox You can create a text box which is capable of capturing multiple lines of text by setting the multiline parameter to True and giving the textbox a height : from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True) app.display() Multi-line text boxes can also be given a scrollbar by setting the scrollbar parameter to True : input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True, scrollbar=True)","title":"TextBox"},{"location":"textbox/#textbox","text":"__init__( self, master, text=\"\", width=10, height=1, grid=None, align=None, visible=True, enabled=None, multiline=False, scrollbar=False, command=None, hide_text=False)","title":"TextBox"},{"location":"textbox/#what-is-it","text":"The TextBox object displays a text box which the user can type in.","title":"What is it"},{"location":"textbox/#how-do-i-make-one","text":"Create a TextBox object like this: from guizero import App, TextBox app = App() input_box = TextBox(app) app.display()","title":"How do I make one?"},{"location":"textbox/#starting-parameters","text":"When you create a TextBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: textbox = TextBox(app, text=\"Please enter some text\") Parameter Data type Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. text string \"\" - Any text you wish to be pre-filled in the text box width int 10 - Set the width of the widget in characters or to \"fill\" height int 1 - Set the height of the widget in characters or to \"fill\" , only effective if multiline is True visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master multiline boolean False No Create a multi-line text box. scrollbar boolean False No Add a vertical scrollbar to a multi-line text box command function name None - The name of a function to call when the text is changed. This function MUST take either zero or one argument, if the function takes one argument the key which was added to the textbox will be returned. hide_text boolean False - When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character.","title":"Starting parameters"},{"location":"textbox/#methods","text":"You can call the following methods on your TextBox object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) append(text) text (string) - Adds the provided text to the end of the current text within the text box cancel(command) command (function name) - Cancels a scheduled call to command clear() - - Clears the textbox destroy() - - Destroys the widget disable() - - Disables the widget so that it is \"greyed out\" and cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. resize(width, height) width (int), height (int) - Sets the width and height of the widget show() - - Displays the widget if it was previously hidden update_command(command) command (function name) - Updates the function to call when the text is changed.","title":"Methods"},{"location":"textbox/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height of the widget in characters or to \"fill\" , only effective if multiline is True hide_text boolean / char When set to True will hide the text replacing typed characters with * . Setting to a character will result in the text being hidden with that character. master App or Box The container to which this widget belongs value string The text in the TextBox visible boolean If this widget is visible width size Set the width of the widget in characters or to \"fill\" text_size int The size of the text text_color color The colour of the text tk tkinter.Entry The internal tkinter object, see Using tkinter","title":"Properties"},{"location":"textbox/#examples","text":"Creating a TextBox with default text You can set the default text in a TextBox when it is created using the text parameter: from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type here\") app.display() Creating a password TextBox with hidden text You can hide the text in a TextBox using the hide_text parameter: from guizero import App, TextBox app = App() password_box = TextBox(app, hide_text=True) app.display() Creating a multi-line TextBox You can create a text box which is capable of capturing multiple lines of text by setting the multiline parameter to True and giving the textbox a height : from guizero import App, TextBox app = App() input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True) app.display() Multi-line text boxes can also be given a scrollbar by setting the scrollbar parameter to True : input_box = TextBox(app, text=\"Type lines here\", height=10, multiline=True, scrollbar=True)","title":"Examples"},{"location":"usingtk/","text":"Using tkinter If you are an advanced user, you can still make use of tkinter when using guizero. You can combine the use of guizero and tkinter seamlessly in a program, taking advantage of the simplified syntax of guizero whilst still being able to access the full range of functionality in tkinter if you need it. Using tkinter widgets in guizero You can add tk widgets into your guizero app using the add_tk_widget method of App , Window and Box . In this example, we are adding the tkinter widget Spinbox into a guizero App : from guizero import App, Text from tkinter import Spinbox app = App() text = Text(app, text=\"A Spinbox widget\") spinbox = Spinbox(from_=0, to=10) app.add_tk_widget(spinbox) app.display() When adding a tk widget to a Box or a Window you will have to specify its tk property when creating the tk widget. box = Box(app) spinbox = Spinbox(box.tk, from_=0, to=10) box.add_tk_widget(spinbox) Using a tkinter method on a guizero object Each guizero widget itself contains a tk widget - you can find out which by looking on the guizero documentation page for the widget. For example, a guizero TextBox contains a tkinter Entry object. You can access the internal object using the syntax .tk . In this example, we have guizero App and TextBox widgets and are using the tk widgets config method to change the mouse cursor when it is over the TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Laura\") name.tk.config(cursor=\"target\") app.display()","title":"Using tkinter"},{"location":"usingtk/#using-tkinter","text":"If you are an advanced user, you can still make use of tkinter when using guizero. You can combine the use of guizero and tkinter seamlessly in a program, taking advantage of the simplified syntax of guizero whilst still being able to access the full range of functionality in tkinter if you need it.","title":"Using tkinter"},{"location":"usingtk/#using-tkinter-widgets-in-guizero","text":"You can add tk widgets into your guizero app using the add_tk_widget method of App , Window and Box . In this example, we are adding the tkinter widget Spinbox into a guizero App : from guizero import App, Text from tkinter import Spinbox app = App() text = Text(app, text=\"A Spinbox widget\") spinbox = Spinbox(from_=0, to=10) app.add_tk_widget(spinbox) app.display() When adding a tk widget to a Box or a Window you will have to specify its tk property when creating the tk widget. box = Box(app) spinbox = Spinbox(box.tk, from_=0, to=10) box.add_tk_widget(spinbox)","title":"Using tkinter widgets in guizero"},{"location":"usingtk/#using-a-tkinter-method-on-a-guizero-object","text":"Each guizero widget itself contains a tk widget - you can find out which by looking on the guizero documentation page for the widget. For example, a guizero TextBox contains a tkinter Entry object. You can access the internal object using the syntax .tk . In this example, we have guizero App and TextBox widgets and are using the tk widgets config method to change the mouse cursor when it is over the TextBox . from guizero import App, TextBox app = App() name = TextBox(app, text=\"Laura\") name.tk.config(cursor=\"target\") app.display()","title":"Using a tkinter method on a guizero object"},{"location":"waffle/","text":"Waffle __init__( self, master, height=3, width=3, dim=20, pad=5, color=\"white\", dotty=False, grid=None, align=None, command=None, remember=True, visible=True, enabled=None, bg=None) What is it The Waffle object display an n*n grid of squares with custom dimensions and padding. How do I make one? Create a Waffle object like this: from guizero import App, Waffle app = App() waffle = Waffle(app) app.display() Starting parameters When you create a Waffle object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: waffle = Waffle(app, height=25) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color \"white\" - The default colour of pixels on the waffle command function name None - The name of a function to call when the waffle is clicked. This function MUST take either zero or two arguments, if the function takes two arguments the x and y co-ordinates of the pixel which was clicked will be given. dim int 20 - How large one of the pixels on the waffle is dotty boolean False - Whether the pixels display as dots/circles (True) or squares (False) grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. height int 3 - Set the height in waffle pixels pad int 5 - How much space is between the pixels on the waffle width int 3 - Set the width in waffle pixels visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master bg color None No The background colour of the waffle. Takes a color value. Methods You can call the following methods on your Waffle object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) get_all() - List Returns the pixel colours in the grid as a 2D list. get_pixel(x, y) x (int), y (int) string Returns the colour of the pixel at the specified coordinates. 0,0 is the top left of the grid. hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. pixel(x, y) (int), y (int) WafflePixel Returns the pixel at the specified coordinates. 0,0 is the top left of the grid. Waffle.pixel(x,y) is the equivalent of Waffle[x,y] repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. set_all(color) color ( color ) - Sets all pixels to the specified colour. set_pixel(x, y, color) x (int), y (int), color ( color ) - Sets the pixel at the specified coordinates to the specified colour. 0,0 is the top left of the grid. show() - - Displays the widget update_command(command) command (function name) - Updates the function to call when the Waffle is clicked Properties You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget color color The default colour of pixels on the waffle dotty bool If True the waffle will display circles enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height in waffle pixels master App or Box The container to which this widget belongs pad int The size of the padding between pixels pixel_size int The size of the one pixel tk tkinter.Frame The internal tkinter object, see Using tkinter width size Set the width in waffle pixels visible boolean If this widget is visible Example Set a pixel colour A Waffle can remember the colour of each pixel within it. from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle[2,1].color = \"red\" # Your waffle will remember what colour each pixel is print(my_waffle[2,1].color) # Even the ones auto-set at the start (which are white by default) print(my_waffle[1,1].color) app.display() WafflePixel A WafflePixel object is returned by Waffle.pixel(x,y) and Waffle[x,y] . from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle.pixel(x,y).color = \"red\" my_waffle[x,y].dotty = True app.display() Properties You can set and get the following properties: Method Data type Description x int Returns the x position of the pixel on the widget x int Returns the y position of the pixel on the widget canvas_x int Returns the x position of the pixel on the canvas canvas_y int Returns the y position of the pixel on the canvas color color Sets or returns the color of the pixel dotty bool Set to True to make the pixel a circle size int Returns the size of the pixel in display pixels","title":"Waffle"},{"location":"waffle/#waffle","text":"__init__( self, master, height=3, width=3, dim=20, pad=5, color=\"white\", dotty=False, grid=None, align=None, command=None, remember=True, visible=True, enabled=None, bg=None)","title":"Waffle"},{"location":"waffle/#what-is-it","text":"The Waffle object display an n*n grid of squares with custom dimensions and padding.","title":"What is it"},{"location":"waffle/#how-do-i-make-one","text":"Create a Waffle object like this: from guizero import App, Waffle app = App() waffle = Waffle(app) app.display()","title":"How do I make one?"},{"location":"waffle/#starting-parameters","text":"When you create a Waffle object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: waffle = Waffle(app, height=25) Parameter Takes Default Compulsory Description master App, Window or Box - Yes The container to which this widget belongs align string None - Alignment of this widget within its container. Possible values: \"top\" , \"bottom\" , \"left\" , \"right\" . color color \"white\" - The default colour of pixels on the waffle command function name None - The name of a function to call when the waffle is clicked. This function MUST take either zero or two arguments, if the function takes two arguments the x and y co-ordinates of the pixel which was clicked will be given. dim int 20 - How large one of the pixels on the waffle is dotty boolean False - Whether the pixels display as dots/circles (True) or squares (False) grid List [int, int] None - [x,y] coordinates of this widget. This parameter is only required if the master object has a grid layout. height int 3 - Set the height in waffle pixels pad int 5 - How much space is between the pixels on the waffle width int 3 - Set the width in waffle pixels visible boolean True No If the widget should be visible. enabled boolean None No If the widget should be enabled. If None (the default) the enabled property will be inherited from the master bg color None No The background colour of the waffle. Takes a color value.","title":"Starting parameters"},{"location":"waffle/#methods","text":"You can call the following methods on your Waffle object. Method Takes Returns Description after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command destroy() - - Destroys the widget disable() - - Disables the widget so that it cannot be interacted with enable() - - Enables the widget focus() - - Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it) get_all() - List Returns the pixel colours in the grid as a 2D list. get_pixel(x, y) x (int), y (int) string Returns the colour of the pixel at the specified coordinates. 0,0 is the top left of the grid. hide() - - Hides the widget from view. This method will unpack the widget from the layout manager. pixel(x, y) (int), y (int) WafflePixel Returns the pixel at the specified coordinates. 0,0 is the top left of the grid. Waffle.pixel(x,y) is the equivalent of Waffle[x,y] repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. set_all(color) color ( color ) - Sets all pixels to the specified colour. set_pixel(x, y, color) x (int), y (int), color ( color ) - Sets the pixel at the specified coordinates to the specified colour. 0,0 is the top left of the grid. show() - - Displays the widget update_command(command) command (function name) - Updates the function to call when the Waffle is clicked","title":"Methods"},{"location":"waffle/#properties","text":"You can set and get the following properties: Method Data type Description align string The alignment of this widget within its container bg color The background colour of the widget color color The default colour of pixels on the waffle dotty bool If True the waffle will display circles enabled boolean True if the widget is enabled grid List [x,y] coordinates of this widget. This parameter is only required if the master object has a grid height size Set the height in waffle pixels master App or Box The container to which this widget belongs pad int The size of the padding between pixels pixel_size int The size of the one pixel tk tkinter.Frame The internal tkinter object, see Using tkinter width size Set the width in waffle pixels visible boolean If this widget is visible","title":"Properties"},{"location":"waffle/#example","text":"Set a pixel colour A Waffle can remember the colour of each pixel within it. from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle[2,1].color = \"red\" # Your waffle will remember what colour each pixel is print(my_waffle[2,1].color) # Even the ones auto-set at the start (which are white by default) print(my_waffle[1,1].color) app.display()","title":"Example"},{"location":"waffle/#wafflepixel","text":"A WafflePixel object is returned by Waffle.pixel(x,y) and Waffle[x,y] . from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle.pixel(x,y).color = \"red\" my_waffle[x,y].dotty = True app.display()","title":"WafflePixel"},{"location":"waffle/#properties_1","text":"You can set and get the following properties: Method Data type Description x int Returns the x position of the pixel on the widget x int Returns the y position of the pixel on the widget canvas_x int Returns the x position of the pixel on the canvas canvas_y int Returns the y position of the pixel on the canvas color color Sets or returns the color of the pixel dotty bool Set to True to make the pixel a circle size int Returns the size of the pixel in display pixels","title":"Properties"},{"location":"widgetoverview/","text":"Overview Widgets are how you create your GUI. They are the things which appear on the GUI, everything from the app itself to text boxes, buttons and pictures. Note: This is an overview of the widgets in guizero. Be sure to view the specific documentation for each widget for more information. Widgets App The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets. app = App() app.display() Box The Box object is an invisible container which can contain other widgets. box = Box(app) box = Box(app, border=True) ButtonGroup The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option. choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"]) CheckBox The CheckBox object displays a check box to allow an option to be ticked or un-ticked. checkbox = CheckBox(app, text=\"salad ?\") Combo The Combo object displays a drop down box allowing a single option to be selected from a list of options. combo = Combo(app, options=[\"cheese\", \"ham\", \"salad\"]) Drawing The Drawing object allows shapes, images and text to be created. drawing = Drawing(app) ListBox The ListBox object displays a list of items from which either single or multiple items can be selected. listbox = ListBox(app, items=[\"cheese\", \"ham\", \"salad\"]) Picture The Picture object displays an image. picture = Picture(app, image=\"guizero.png\") PushButton The PushButton object displays a button with text or an image, which calls a function when pressed. def do_nothing(): print(\"button pressed\") button = PushButton(app, command=do_nothing) Slider The Slider object displays a bar and selector which can be used to specify a value in a range. slider = Slider(app) Text The Text object displays non editable text in your app, useful for titles, labels and instructions. text = Text(app, text=\"Hello World\") TextBox The TextBox object displays a text box which the user can type in. textbox = TextBox(app) Waffle The Waffle object display an n*n grid of squares with custom dimensions and padding. waffle = Waffle(app) Window The Window object create a new window in guizero. window = Window(app) Properties All widgets are customisable through their properties. These properties are typical for most widgets. Check the widgets document for more information. Property Data type Description align string The alignment of this widget within its container bg string, List The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget if in a \"grid\". height int, string The height of the widget. master App, Window, Box The container to which this widget belongs value int, string, bool The widgets current \"value\", e.g. the text in a TextBox visible boolean If this widget is visible width size The width of the widget. text_size int The size of the text text_color color The colour of the text Methods Widgets can be interacted with through their methods. The methods supported are dependent on the widget, so check the documentation. These methods are typical across most widgets. Method Description after(time, command, args=None) Schedules a single call to command after time milliseconds cancel(command) Cancels a scheduled call to command destroy() Destroys the widget disable() Disables the widget so that it cannot be interacted with enable() Enables the widget focus() Gives focus to the widget hide() Hides the widget from view repeat(time, command, args=None) Schedules a call to command every time milliseconds resize(width, height) Sets the width and height of the widget show() Displays the widget if it was previously hidden update_command(command, args =None) Updates the function to call when the widget is used","title":"Overview"},{"location":"widgetoverview/#overview","text":"Widgets are how you create your GUI. They are the things which appear on the GUI, everything from the app itself to text boxes, buttons and pictures. Note: This is an overview of the widgets in guizero. Be sure to view the specific documentation for each widget for more information.","title":"Overview"},{"location":"widgetoverview/#widgets","text":"","title":"Widgets"},{"location":"widgetoverview/#app","text":"The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets. app = App() app.display()","title":"App"},{"location":"widgetoverview/#box","text":"The Box object is an invisible container which can contain other widgets. box = Box(app) box = Box(app, border=True)","title":"Box"},{"location":"widgetoverview/#buttongroup","text":"The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option. choice = ButtonGroup(app, options=[\"cheese\", \"ham\", \"salad\"])","title":"ButtonGroup"},{"location":"widgetoverview/#checkbox","text":"The CheckBox object displays a check box to allow an option to be ticked or un-ticked. checkbox = CheckBox(app, text=\"salad ?\")","title":"CheckBox"},{"location":"widgetoverview/#combo","text":"The Combo object displays a drop down box allowing a single option to be selected from a list of options. combo = Combo(app, options=[\"cheese\", \"ham\", \"salad\"])","title":"Combo"},{"location":"widgetoverview/#drawing","text":"The Drawing object allows shapes, images and text to be created. drawing = Drawing(app)","title":"Drawing"},{"location":"widgetoverview/#listbox","text":"The ListBox object displays a list of items from which either single or multiple items can be selected. listbox = ListBox(app, items=[\"cheese\", \"ham\", \"salad\"])","title":"ListBox"},{"location":"widgetoverview/#picture","text":"The Picture object displays an image. picture = Picture(app, image=\"guizero.png\")","title":"Picture"},{"location":"widgetoverview/#pushbutton","text":"The PushButton object displays a button with text or an image, which calls a function when pressed. def do_nothing(): print(\"button pressed\") button = PushButton(app, command=do_nothing)","title":"PushButton"},{"location":"widgetoverview/#slider","text":"The Slider object displays a bar and selector which can be used to specify a value in a range. slider = Slider(app)","title":"Slider"},{"location":"widgetoverview/#text","text":"The Text object displays non editable text in your app, useful for titles, labels and instructions. text = Text(app, text=\"Hello World\")","title":"Text"},{"location":"widgetoverview/#textbox","text":"The TextBox object displays a text box which the user can type in. textbox = TextBox(app)","title":"TextBox"},{"location":"widgetoverview/#waffle","text":"The Waffle object display an n*n grid of squares with custom dimensions and padding. waffle = Waffle(app)","title":"Waffle"},{"location":"widgetoverview/#window","text":"The Window object create a new window in guizero. window = Window(app)","title":"Window"},{"location":"widgetoverview/#properties","text":"All widgets are customisable through their properties. These properties are typical for most widgets. Check the widgets document for more information. Property Data type Description align string The alignment of this widget within its container bg string, List The background colour of the widget enabled boolean True if the widget is enabled font string The font of the text grid List [x,y] coordinates of this widget if in a \"grid\". height int, string The height of the widget. master App, Window, Box The container to which this widget belongs value int, string, bool The widgets current \"value\", e.g. the text in a TextBox visible boolean If this widget is visible width size The width of the widget. text_size int The size of the text text_color color The colour of the text","title":"Properties"},{"location":"widgetoverview/#methods","text":"Widgets can be interacted with through their methods. The methods supported are dependent on the widget, so check the documentation. These methods are typical across most widgets. Method Description after(time, command, args=None) Schedules a single call to command after time milliseconds cancel(command) Cancels a scheduled call to command destroy() Destroys the widget disable() Disables the widget so that it cannot be interacted with enable() Enables the widget focus() Gives focus to the widget hide() Hides the widget from view repeat(time, command, args=None) Schedules a call to command every time milliseconds resize(width, height) Sets the width and height of the widget show() Displays the widget if it was previously hidden update_command(command, args =None) Updates the function to call when the widget is used","title":"Methods"},{"location":"window/","text":"Window __init__( self, master, title=\"guizero\", width=500, height=500, layout=\"auto\", bg=None, visible=True) What is it? The Window object create a new window in guizero. How do I make one? Create an Window object like this: from guizero import App, Window app = App() window = Window(app) app.display() Starting parameters When you create a Window object you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets like this: window = Window(app, bg=\"red\", height=200) Parameter Data type Default Compulsory Description master App - Yes The app to which the window belongs bg color None No The background colour of the window. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the window should be visible. Methods You can call the following methods on a Window object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the window so that they cannot be interacted with destroy() - - Destroys the windows enable() - - Enables all the widgets in the window error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the window hide() - - Hides the window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show(wait = False) - - Displays the window if it was previously hidden update() - - Force the window to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window. Properties You can set and get the following properties: Method Data type Description bg color The background colour of the window children List A list of widgets in this container enabled boolean True if the window is enabled font string The font that widgets should use full_screen boolean False height int The height of the window layout string The layout being used by the Window ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use tk tkinter.TopLevel The internal tkinter object, see Using tkinter visible boolean If the window is visible width int The width of the window when_closed function The function to call when the Window is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your Window object is called window you would write window.title . You can set the property (for example window.title = \"Hello world\" ) or get the value of the property to use (for example print(window.title) ). Examples Creating a Window object Create an Window object by calling the Window() constructor. You should give the object a name so you can refer to it later - in this case we have called it window . It is best to keep the name you give to your Window object quite short, as you will have to use it to tell other widgets where they should be stored. from guizero import App, Window app = App(title=\"My app\", height=300, width=200) window = Window(title = \"2nd Window\", height=300, width=200) app.display() Showing and hiding a Window Window objects can be shown and hidden using the show() and hide() methods: from guizero import App, Window, PushButton def open_window(): window_2.show() app = App(title=\"My app\", height=300, width=200) window = Window(app, title = \"2nd Window\", height=300, width=200) window.hide() open_button(app, text=\"open 2nd window\", command=open_window) app.display() If you want a Window to become the main window and stop all other windows responding until it is closed you can set the optional wait parameter to True when using show : def open_window(): window_2.show(wait = True)","title":"Window"},{"location":"window/#window","text":"__init__( self, master, title=\"guizero\", width=500, height=500, layout=\"auto\", bg=None, visible=True)","title":"Window"},{"location":"window/#what-is-it","text":"The Window object create a new window in guizero.","title":"What is it?"},{"location":"window/#how-do-i-make-one","text":"Create an Window object like this: from guizero import App, Window app = App() window = Window(app) app.display()","title":"How do I make one?"},{"location":"window/#starting-parameters","text":"When you create a Window object you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets like this: window = Window(app, bg=\"red\", height=200) Parameter Data type Default Compulsory Description master App - Yes The app to which the window belongs bg color None No The background colour of the window. Takes a color value. height int 500 No The height of the window in pixels. layout string \"auto\" No Whether widgets pack themselves ( \"auto\" ) or you specify their position on a grid ( \"grid\" ) title string \"guizero\" No The title displayed in the bar at the top of the window. width int 500 No The width of the window in pixels. visible boolean True No If the window should be visible.","title":"Starting parameters"},{"location":"window/#methods","text":"You can call the following methods on a Window object. Method Takes Returns Description add_tk_widget(tk_widget, grid=None, align=None, visible=True, enabled=None, width=None, height=None) tk_widget (tk), grid (list), align (str), visible (bool), enabled (bool), width (int), height (int) Widget Adds a tk widget into a guizero container. Note - this is an advanced feature see Using tk for more information. after(time, command, args=None) time (int), command (function name), args (list of arguments) - Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat() ) cancel(command) command (function name) - Cancels a scheduled call to command disable() - - Disables all the widgets in the window so that they cannot be interacted with destroy() - - Destroys the windows enable() - - Enables all the widgets in the window error(title, text) title (str), text (str) - Displays a popup box with an error icon exit_full_screen() - - Exit full screen display focus() - - Gives focus to the window hide() - - Hides the window from view. info(title, text) title (str), text (str) - Displays a popup box with an information icon question(title, text, initial_value=None) title (str), text (str), initial_value (str) Pressing Ok returns value entered into the box is returned and pressing Cancel returns None Displays a popup box with a question box which can accept a text response repeat(time, command, args=None) time (int), command (function name), args (list of arguments) - Repeats command every time milliseconds. This is useful for scheduling a function to be regularly called, for example updating a value read from a sensor. select_file(title=\"Select file\", folder=\".\", filetypes=[[\"All files\", \" . \"]], save=False) title (str), folder (str), filetypes (list), save (bool) Full path of the file selected as a string Display a box to select a file to open or save. If Open or Save is pressed the filename path is returned. If Cancel is pressed None is returned. select_folder(title=\"Select folder\", folder=\".\") title (str), folder (str) Full path of the folder selected as a string Display a box to select a folder. If a folder is selected the folder path is returned, otherwise None is returned. set_full_screen(keybind) String - Set the application to display full screen. Option to specify a key to exit full screen (default is 'Esc'.) show(wait = False) - - Displays the window if it was previously hidden update() - - Force the window to update itself, useful if changes aren't reflected in the UI. warn(title, text) title (str), text (str) - Displays a popup box with a warning icon yesno(title, text) title (str), text (str) Pressing Yes returns True and pressing No returns False Displays a popup box with yes and no options on_close(command) command (function name) - Calls the given function when the user tries to close the window.","title":"Methods"},{"location":"window/#properties","text":"You can set and get the following properties: Method Data type Description bg color The background colour of the window children List A list of widgets in this container enabled boolean True if the window is enabled font string The font that widgets should use full_screen boolean False height int The height of the window layout string The layout being used by the Window ( \"auto\" ) or ( \"grid\" ) title string The title of the window text_size int The size of the text widgets should use text_color color The colour of the text widgets should use tk tkinter.TopLevel The internal tkinter object, see Using tkinter visible boolean If the window is visible width int The width of the window when_closed function The function to call when the Window is closed. Setting to None (the default) will reset. Refer to a property as .property . For example, if your Window object is called window you would write window.title . You can set the property (for example window.title = \"Hello world\" ) or get the value of the property to use (for example print(window.title) ).","title":"Properties"},{"location":"window/#examples","text":"Creating a Window object Create an Window object by calling the Window() constructor. You should give the object a name so you can refer to it later - in this case we have called it window . It is best to keep the name you give to your Window object quite short, as you will have to use it to tell other widgets where they should be stored. from guizero import App, Window app = App(title=\"My app\", height=300, width=200) window = Window(title = \"2nd Window\", height=300, width=200) app.display() Showing and hiding a Window Window objects can be shown and hidden using the show() and hide() methods: from guizero import App, Window, PushButton def open_window(): window_2.show() app = App(title=\"My app\", height=300, width=200) window = Window(app, title = \"2nd Window\", height=300, width=200) window.hide() open_button(app, text=\"open 2nd window\", command=open_window) app.display() If you want a Window to become the main window and stop all other windows responding until it is closed you can set the optional wait parameter to True when using show : def open_window(): window_2.show(wait = True)","title":"Examples"}]}
    \ No newline at end of file
    diff --git a/docs/search/worker.js b/docs/search/worker.js
    index 9cce2f79..a3ccc07f 100644
    --- a/docs/search/worker.js
    +++ b/docs/search/worker.js
    @@ -58,7 +58,6 @@ function onScriptsLoaded () {
       if (data.config && data.config.separator && data.config.separator.length) {
         lunr.tokenizer.separator = new RegExp(data.config.separator);
       }
    -
       if (data.index) {
         index = lunr.Index.load(data.index);
         data.docs.forEach(function (doc) {
    @@ -85,7 +84,6 @@ function onScriptsLoaded () {
         console.log('Lunr index built, search ready');
       }
       allowSearch = true;
    -  postMessage({config: data.config});
       postMessage({allowSearch: allowSearch});
     }
     
    diff --git a/docs/sitemap.xml b/docs/sitemap.xml
    index cb06086b..81a2b127 100644
    --- a/docs/sitemap.xml
    +++ b/docs/sitemap.xml
    @@ -1,147 +1,147 @@
     
     
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
          None
    -     2020-10-28
    +     2020-11-27
          daily
         
     
    \ No newline at end of file
    diff --git a/docs/sitemap.xml.gz b/docs/sitemap.xml.gz
    index e126e6a27210293762571e0a3c44f0797af5d9b0..2d771e23583cb43df39fe8cbb01efd2904050c56 100644
    GIT binary patch
    literal 215
    zcmV;|04V<-iwFqL=fGbA|8r?{Wo=<_E_iKh0PWYk4uc>R1>oJMAnby=^e2d0$4>17
    z5Tr_iV1d^5?F+^xeT62M1vs3WZ-#ZR$)Kn5K|9;xnp7AmD_yVc(BkXmRPJ%d3-<6P
    zsEAV8h8B-8&PPg@Wg$UFHHkS8=LZ_(m@a{CA+5*(^E}H7lovBj^0Tvw(R})bBE-q{
    zys4V1tn0GbrROc%DsmKdP&cpcycgQM8U0Dt4x^a?3oNj}0t+m#zyb>_u)qQftbehJ
    RbxXf({s99|rkkA)003-OXP^K8
    
    literal 214
    zcmb2|=HOVre`Y+>|KiM&)ZD}Zy^7o%hPT%Z`3@ufl{ghZ^V-`JJwy+8LO
    NqvDPu<#YKN7yz%EUeo{p
    
    diff --git a/docs/size/index.html b/docs/size/index.html
    index c96e240e..721af046 100644
    --- a/docs/size/index.html
    +++ b/docs/size/index.html
    @@ -349,7 +349,7 @@ 

    Sizes

    You can set the width and height of widgets in guizero.

    Widgets are sized by either pixels or characters depending on the widget and what it contains.

    Some widgets size can also be set to "fill" where it will use up all of the available space.

    -
    from guizero import App, PushButton, Slider, ListBox
    +
    from guizero import App, PushButton, Slider, ListBox
     
     app = App()
     
    @@ -364,6 +364,7 @@ 

    Sizes

    app.display()
    + diff --git a/docs/slider/index.html b/docs/slider/index.html index 8b3847c1..f57fa6f5 100644 --- a/docs/slider/index.html +++ b/docs/slider/index.html @@ -358,8 +358,7 @@

    Slider

    -

    (Contains a tkinter.Scale object)

    -
    __init__(
    +
    __init__(
         self, 
         master, 
         start=0, 
    @@ -373,17 +372,19 @@ 

    Slider

    width=None, height=None)
    +

    What is it?

    The Slider object displays a bar and selector which can be used to specify a value in a range.

    The above code looks like this on Windows: Slider on Windows

    How do I make one?

    Create a Slider object like this:

    -
    from guizero import App, Slider
    +
    from guizero import App, Slider
     app = App()
     slider = Slider(app)
     app.display()
     
    +

    Starting paramters

    When you create a Slider object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: slider = Slider(app, horizontal=False)

    @@ -619,6 +620,11 @@

    Properties

    + + + + + @@ -640,7 +646,7 @@

    Examples

    You can specify a function to call when the slider value changes. Your function MUST have a minimum of one parameter as it will automatically receive a string containing the value of the slider (called slider_value in the example) when it is called.

    This code has a slider and a text box, and the text box updates automatically to display the current value of the slider.

    Text box and slider

    -
    from guizero import App, Slider, TextBox
    +
    from guizero import App, Slider, TextBox
     def slider_changed(slider_value):
         textbox.value = slider_value
     
    diff --git a/docs/start/index.html b/docs/start/index.html
    index 1d35687d..f8cbf46c 100644
    --- a/docs/start/index.html
    +++ b/docs/start/index.html
    @@ -351,29 +351,33 @@
     
     

    Getting Started

    At the start of every guizero program, choose the widgets you need from the guizero library and import them:

    -
    from guizero import App, PushButton, Slider
    +
    from guizero import App, PushButton, Slider
     
    +

    You only need to import each widget once, and then you can use it in your program as many times as you like.

    Hello World

    All guizero projects begin with a main window which is called an App. At the end of every guizero program you must tell the program to display the app you have just created.

    Let's create an app window with the title "Hello world":

    -
    from guizero import App
    +
    from guizero import App
     app = App(title="Hello world")
     app.display()
     
    +

    Save and run the code - you've created your first guizero app!

    Adding widgets

    Widgets are the things which appear on the GUI, such as text boxes, buttons, sliders and even plain old pieces of text.

    All widgets go between the line of code to create the App and the app.display() line.

    -
    from guizero import App, Text
    +
    from guizero import App, Text
     app = App(title="Hello world")
     message = Text(app, text="Welcome to the Hello world app!")
     app.display()
     
    +

    Hello world

    Let’s look at the Text widget code in a bit more detail:

    -
    message = Text(app, text="Welcome to the Hello world app!")
    +
    message = Text(app, text="Welcome to the Hello world app!")
     
    +
    • message = - The Text object has a name, just like any variable
    • Text - an object which creates a piece of text on the screen
    • diff --git a/docs/text/index.html b/docs/text/index.html index 2139357e..74a5043d 100644 --- a/docs/text/index.html +++ b/docs/text/index.html @@ -356,8 +356,7 @@

      Text

      -

      (Contains a tkinter.Label object)

      -
      __init__(
      +
      __init__(
           self,
           master,
           text="",
      @@ -372,16 +371,18 @@ 

      Text

      width=None, height=None)
      +

      What is it?

      The Text object displays non editable text in your app, useful for titles, labels and instructions.

      Text on Windows

      How do I make one?

      Create a Text object like this:

      -
      from guizero import App, Text
      +
      from guizero import App, Text
       app = App()
       text = Text(app, text="Hello World")
       app.display()
       
      +

      Starting parameters

      When you create a Text object, you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets, like this: text = Text(app, text="hi")

    The colour of the text
    tktkinter.ScaleThe internal tkinter object, see Using tkinter
    value string The current value of the slider
    @@ -617,6 +618,11 @@

    Properties

    + + + + + diff --git a/docs/textbox/index.html b/docs/textbox/index.html index 24f0a992..e81f3eb5 100644 --- a/docs/textbox/index.html +++ b/docs/textbox/index.html @@ -358,8 +358,7 @@

    TextBox

    -

    (Contains a tkinter.Entry object)

    -
    __init__(
    +
    __init__(
         self,
         master,
         text="",
    @@ -374,16 +373,18 @@ 

    TextBox

    command=None, hide_text=False)
    +

    What is it

    The TextBox object displays a text box which the user can type in.

    TextBox on Windows

    How do I make one?

    Create a TextBox object like this:

    -
    from guizero import App, TextBox
    +
    from guizero import App, TextBox
     app = App()
     input_box = TextBox(app)
     app.display()
     
    +

    Starting parameters

    When you create a TextBox object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: textbox = TextBox(app, text="Please enter some text")

    The colour of the text
    tktkinter.LabelThe internal tkinter object, see Using tkinter
    value string The text
    @@ -651,32 +652,40 @@

    Properties

    + + + + +
    color The colour of the text
    tktkinter.EntryThe internal tkinter object, see Using tkinter

    Examples

    Creating a TextBox with default text

    You can set the default text in a TextBox when it is created using the text parameter:

    -
    from guizero import App, TextBox
    +
    from guizero import App, TextBox
     app = App()
     input_box = TextBox(app, text="Type here")
     app.display()
     
    +

    Creating a password TextBox with hidden text

    You can hide the text in a TextBox using the hide_text parameter:

    -
    from guizero import App, TextBox
    +
    from guizero import App, TextBox
     app = App()
     password_box = TextBox(app, hide_text=True)
     app.display()
     
    +

    Creating a multi-line TextBox

    You can create a text box which is capable of capturing multiple lines of text by setting the multiline parameter to True and giving the textbox a height:

    -
    from guizero import App, TextBox
    +
    from guizero import App, TextBox
     app = App()
     input_box = TextBox(app, text="Type lines here", height=10, multiline=True)
     app.display()
     
    +

    Multi-line text boxes can also be given a scrollbar by setting the scrollbar parameter to True:

    -
    input_box = TextBox(app, text="Type lines here", height=10, multiline=True, scrollbar=True)
    +
    input_box = TextBox(app, text="Type lines here", height=10, multiline=True, scrollbar=True)
     
    diff --git a/docs/usingtk/index.html b/docs/usingtk/index.html index c3fa15b0..fa6a8bf5 100644 --- a/docs/usingtk/index.html +++ b/docs/usingtk/index.html @@ -355,7 +355,7 @@

    Using tkinter

    Using tkinter widgets in guizero

    You can add tk widgets into your guizero app using the add_tk_widget method of App, Window and Box.

    In this example, we are adding the tkinter widget Spinbox into a guizero App:

    -
    from guizero import App, Text
    +
    from guizero import App, Text
     from tkinter import Spinbox
     
     app = App()
    @@ -366,15 +366,17 @@ 

    Using tkinter widgets in guizero

    app.display()
    +

    When adding a tk widget to a Box or a Window you will have to specify its tk property when creating the tk widget.

    -
    box = Box(app)
    +
    box = Box(app)
     spinbox = Spinbox(box.tk, from_=0, to=10)
     box.add_tk_widget(spinbox)
     
    +

    Using a tkinter method on a guizero object

    Each guizero widget itself contains a tk widget - you can find out which by looking on the guizero documentation page for the widget. For example, a guizero TextBox contains a tkinter Entry object. You can access the internal object using the syntax <object_name>.tk.

    In this example, we have guizero App and TextBox widgets and are using the tk widgets config method to change the mouse cursor when it is over the TextBox.

    -
    from guizero import App, TextBox
    +
    from guizero import App, TextBox
     app = App()
     name = TextBox(app, text="Laura")
     name.tk.config(cursor="target") 
    diff --git a/docs/waffle/index.html b/docs/waffle/index.html
    index 043c9d49..c0343795 100644
    --- a/docs/waffle/index.html
    +++ b/docs/waffle/index.html
    @@ -361,8 +361,7 @@
             

    Waffle

    -

    (Contains a tkinter.Frame object)

    -
    __init__(
    +
    __init__(
         self, 
         master, 
         height=3, 
    @@ -379,16 +378,18 @@ 

    Waffle

    enabled=None, bg=None)
    +

    What is it

    The Waffle object display an n*n grid of squares with custom dimensions and padding.

    Waffle on Windows

    How do I make one?

    Create a Waffle object like this:

    -
    from guizero import App, Waffle
    +
    from guizero import App, Waffle
     app = App()
     waffle = Waffle(app)
     app.display()
     
    +

    Starting parameters

    When you create a Waffle object you must specify master and you can specify any of the optional parameters. Specify parameters in the brackets, like this: waffle = Waffle(app, height=25)

    @@ -661,6 +662,11 @@

    Properties

    + + + + + @@ -675,7 +681,7 @@

    Properties

    Example

    Set a pixel colour

    A Waffle can remember the colour of each pixel within it.

    -
    from guizero import App, Waffle
    +
    from guizero import App, Waffle
     
     app = App()
     
    @@ -690,9 +696,10 @@ 

    Example

    app.display()
    +

    WafflePixel

    A WafflePixel object is returned by Waffle.pixel(x,y) and Waffle[x,y].

    -
    from guizero import App, Waffle
    +
    from guizero import App, Waffle
     
     app = App()
     
    @@ -702,6 +709,7 @@ 

    WafflePixel

    app.display()
    +

    Properties

    You can set and get the following properties:

    The size of the one pixel
    tktkinter.FrameThe internal tkinter object, see Using tkinter
    width size Set the width in waffle pixels
    diff --git a/docs/widgetoverview/index.html b/docs/widgetoverview/index.html index 4cc740c7..ec610549 100644 --- a/docs/widgetoverview/index.html +++ b/docs/widgetoverview/index.html @@ -372,78 +372,92 @@

    Widgets

    App

    The App object is the basis of all GUIs created using guizero. It is the main window which contains all of the other widgets.

    guizero App widget

    -
    app = App()
    +
    app = App()
     app.display()
     
    +

    Box

    The Box object is an invisible container which can contain other widgets.

    guizero Box widget

    -
    box = Box(app)
    +
    box = Box(app)
     box = Box(app, border=True)
     
    +

    ButtonGroup

    The ButtonGroup object displays a group of radio buttons, allowing the user to choose a single option.

    guizero ButtonGroup widget

    -
    choice = ButtonGroup(app, options=["cheese", "ham", "salad"])
    +
    choice = ButtonGroup(app, options=["cheese", "ham", "salad"])
     
    +

    CheckBox

    The CheckBox object displays a check box to allow an option to be ticked or un-ticked.

    guizero CheckBox widget

    -
    checkbox = CheckBox(app, text="salad ?")
    +
    checkbox = CheckBox(app, text="salad ?")
     
    +

    Combo

    The Combo object displays a drop down box allowing a single option to be selected from a list of options.

    guizero Combo widget

    -
    combo = Combo(app, options=["cheese", "ham", "salad"])
    +
    combo = Combo(app, options=["cheese", "ham", "salad"])
     
    +

    Drawing

    The Drawing object allows shapes, images and text to be created.

    guizero Drawing widget

    -
    drawing = Drawing(app)
    +
    drawing = Drawing(app)
     
    +

    ListBox

    The ListBox object displays a list of items from which either single or multiple items can be selected.

    guizero ListBox widget

    -
    listbox = ListBox(app, items=["cheese", "ham", "salad"])
    +
    listbox = ListBox(app, items=["cheese", "ham", "salad"])
     
    +

    Picture

    The Picture object displays an image.

    guizero Picture widget

    -
    picture = Picture(app, image="guizero.png")
    +
    picture = Picture(app, image="guizero.png")
     
    +

    PushButton

    The PushButton object displays a button with text or an image, which calls a function when pressed.

    guizero PushButton widget

    -
    def do_nothing():
    +
    def do_nothing():
         print("button pressed")
     
     button = PushButton(app, command=do_nothing)
     
    +

    Slider

    The Slider object displays a bar and selector which can be used to specify a value in a range.

    guizero Slider widget

    -
    slider = Slider(app)
    +
    slider = Slider(app)
     
    +

    Text

    The Text object displays non editable text in your app, useful for titles, labels and instructions.

    guizero Text widget

    -
    text = Text(app, text="Hello World")
    +
    text = Text(app, text="Hello World")
     
    +

    TextBox

    The TextBox object displays a text box which the user can type in.

    guizero TextBox widget

    -
    textbox = TextBox(app)
    +
    textbox = TextBox(app)
     
    +

    Waffle

    The Waffle object display an n*n grid of squares with custom dimensions and padding.

    guizero Waffle widget

    -
    waffle = Waffle(app)
    +
    waffle = Waffle(app)
     
    +

    Window

    The Window object create a new window in guizero.

    guizero Waffle widget

    -
    window = Window(app)
    +
    window = Window(app)
     
    +

    Properties

    All widgets are customisable through their properties. These properties are typical for most widgets. Check the widgets document for more information.

    diff --git a/docs/window/index.html b/docs/window/index.html index 1ba8af8d..c2611fc2 100644 --- a/docs/window/index.html +++ b/docs/window/index.html @@ -358,8 +358,7 @@

    Window

    -

    (Contains a tkinter.TopLevel object)

    -
    __init__(
    +
    __init__(
         self, 
         master, 
         title="guizero", 
    @@ -369,16 +368,18 @@ 

    Window

    bg=None, visible=True)
    +

    What is it?

    The Window object create a new window in guizero.

    Window

    How do I make one?

    Create an Window object like this:

    -
    from guizero import App, Window
    +
    from guizero import App, Window
     app = App()
     window = Window(app)
     app.display()
     
    +

    Starting parameters

    When you create a Window object you must specify a master and you can specify any of the the optional parameters. Specify parameters in the brackets like this: window = Window(app, bg="red", height=200)

    @@ -601,7 +602,7 @@

    Properties

    - + @@ -645,6 +646,11 @@

    Properties

    + + + + + @@ -666,14 +672,15 @@

    Properties

    Examples

    Creating a Window object

    Create an Window object by calling the Window() constructor. You should give the object a name so you can refer to it later - in this case we have called it window. It is best to keep the name you give to your Window object quite short, as you will have to use it to tell other widgets where they should be stored.

    -
    from guizero import App, Window
    +
    from guizero import App, Window
     app = App(title="My app", height=300, width=200)
     window = Window(title = "2nd Window", height=300, width=200)
     app.display()
     
    +

    Showing and hiding a Window

    Window objects can be shown and hidden using the show() and hide() methods:

    -
    from guizero import App, Window, PushButton
    +
    from guizero import App, Window, PushButton
     
     def open_window():
         window_2.show()
    @@ -686,8 +693,9 @@ 

    Examples

    app.display()
    +

    If you want a Window to become the main window and stop all other windows responding until it is closed you can set the optional wait parameter to True when using show:

    -
    def open_window():
    +
    def open_window():
         window_2.show(wait = True)
     
    diff --git a/guizero/__init__.py b/guizero/__init__.py index 668a3d6d..75e9710f 100644 --- a/guizero/__init__.py +++ b/guizero/__init__.py @@ -1,6 +1,6 @@ __name__ = "guizero" __package__ = "guizero" -__version__ = '1.1.0' +__version__ = '1.1.1' __author__ = "Laura Sach" from sys import exit
    childrenlist(widgets)List A list of widgets in this container
    The colour of the text widgets should use
    tktkinter.TopLevelThe internal tkinter object, see Using tkinter
    visible boolean If the window is visible