Skip to content

Commit

Permalink
Version 0.4 (#81)
Browse files Browse the repository at this point in the history
* Update readme

* Make the Waffle clickable (#28)

* Adding List GUI option

* Adding clickability to the Waffle

* Stashing new List widget

* Add linux installation and make all subheadings h2 (#42)

* Add updated versions of slider and text widgets

* Fix bug with bgcolor and text_color

* Add changes to ButtonGroup

* Add changes to PushButton

* Fixes #39

* Add changes for Picture

* Add changes to TextBox

* Add changes to CheckBox

* Updates to CheckBox and Combo

* Add changes to MenuBar and Waffle

* Fix autopack, hide attributes, add changes to App and Box

* Add changelog

* Update changelog

* Fixed waffle init bug courtesy of @jjsanderson

* Rename size and add height and width

* Add widget import

* Create Widget.py (#57)

* Waffle updated to update rather than redraw pixels (#61)

* Update changelog.md

* Update Widget.py (#62)

Bug fix: `tk.grid_info` -> `self.tk.grid_info`

* Update Widget.py (#68)

* Fixed `tk.update` calls (#71)

* Update Picture.py (testing)

* Catch only `tk.TclError` instead of all exceptions
* The `master` argument is required for testing. See https://stackoverflow.com/questions/23224574/tkinter-create-image-function-error-pyimage1-does-not-exist

* Fixed `NameError`

* Fix #69 wrong ButtonGroup layout

* Update Picture.py

* Partial docs-src update

Closes #30 #36
Updated widgets up to and including ButtonGroup
Still needs work in using guizero section

* _Widget cancel fix

* after/next *args fix

* added editor detritus to gitignore

* removed .vscode

* updated after repeat

* created tkmixins, updated App

* Add more updated docs up to PushButton

* refactored _Widget

* Cleaned up

* Replaced `type(master)` with `isinstance` check
* Replaced `range(len(toplevel))` with `toplevel` (assuming it's iterable)
* `i` → `menu`

* Removed reference to _Widget

* fixed MenuBar

* added Waffle properties and examples

* removed size mixin

* removed waffle remember

* updated Slider docs

* updated Text docs

* updated TextBox docs

* updated Waffle docs

* fixed examples

* updated docs with the common methods

* doc fixes

* bump version to 0.4.0

* updated PushButton value

* updated PushButton value

* Need Waffle to still accept remember parameter

For backwards compatibility

* Add updated docs-src

* Add generated HTML for new docs

* Remove debug message in toggle function

* Update mistake in pushbutton docs

* Update changelog and readme

* Update readme again

* Add changelog link

* Update changelog

* Update ButtonGroup.py (#80)

* `get_group_as_list` is now a one-liner
* `StringVar` `master` is now the toplevel tkinter widget (required for testing)

* fixed ButtonGroup

* Add upgrade instructions

* List upgrade instructions
  • Loading branch information
lawsie committed Dec 19, 2017
1 parent a3a7d80 commit 16f5761
Show file tree
Hide file tree
Showing 110 changed files with 7,535 additions and 4,697 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,10 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor detritus
*.vim
*.swp
tags
.vscode
.idea
80 changes: 59 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,79 @@
## gui zero
# guizero

Version 0.3.3 (7th June 2017)
[Version 0.4](changelog.md) (19th December 2017)

## Installing with pip
guizero is designed to allow children to quickly and easily create GUIs for their programs.

**Raspberry Pi / Linux**
```bash
sudo pip3 install guizero
```
If you can download and unzip a file, you can use guizero - **no special permissions or administrator rights are required**.

**Windows**
```bash
pip install guizero
```
[Help, I don't know how to install something with pip](http://catcatcode.com/blog/installing-python-packages-with-pip/)
guizero only requires `tkinter` to be installed, which is included with a standard Python installation on all platforms except Linux.

**Upgrading**
```bash
sudo pip3 install -U guizero (on Raspberry Pi)
pip install guizero --upgrade (on Windows)
```
## Easy installation - all platforms

# Mission statement
Use this installation method if you do not have access to a terminal or command prompt on your computer.

1. Click the green "Clone or download" button and then "Download ZIP"

![Download the zip](images/download-zip.png)

2. Unzip the file

3. Open the `guizero-master` folder, then copy the `guizero` folder and paste it into your home directory

![Copy the guizero folder](images/copy-guizero.png)

4. That's it! When you write your guizero code, make sure you save it into your home directory.

## Other installation methods

If you have administrator rights to your computer and are connected to the internet, you can use pip to quickly install guizero.

### Windows

1. Make sure you have pip installed - follow [this guide](https://projects.raspberrypi.org/en/projects/using-pip-on-windows) if you are not sure.
2. Open a command prompt
3. Type `pip install guizero` and press Enter

### Raspberry Pi

1. Open a terminal window
2. Type `sudo pip3 install guizero` and press Enter

### On Mac
1. Open a terminal (you can search for it in the Launch Pad)

![Mac terminal](images/mac-terminal.png)

2. Type `sudo pip3 install guizero`

![Mac install screenshot](images/mac-install.png)

### On Linux

1. Open a terminal
2. Install `tkinter` using your distribution's package manager, e.g. `sudo apt install python3-tk`
3. Install guizero using pip by typing `sudo pip3 install guizero`

## Upgrading

- Raspberry Pi/Linux/Mac - `sudo pip3 install -U guizero`
- Windows - `pip install guizero --upgrade`

## Mission statement
The aim of guizero is to make the process of creating simple GUIs quick, accessible and understandable for children.

# Aims
## Aims
* Works with standard Python GUI library (and no need to install other libraries)
* Abstracts away details children find hard (such as Tkinter StringVar() objects)
* Accessible widget naming system to help children 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](http://lawsie.github.io/guizero)
* Helpful error messages

# Documentation
## Documentation

[http://lawsie.github.io/guizero](http://lawsie.github.io/guizero)

# Contributing
## Contributing

Contributions are welcome - please create a pull request for each fix/addition. The documentation for the latest release is in /docs as HTML files. Please edit the .md files inside /docs-src/docs folder to add documentation for a new feature.
58 changes: 58 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# guizero 0.4 - What’s new?

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](https://github.com/bcroston), [bennuttall](https://github.com/bennuttall), [Coal0](https://github.com/Coal0), [martinohanlon](https://github.com/martinohanlon) and [scotty3785](https://github.com/scotty3785)

I am also very pleased to announce that [martinohanlon](https://github.com/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](https://github.com/bennuttall))
- Improved use of library with tab complete editors (e.g. ipython) – only the guizero properties and methods are listed so the list is shorter and more friendly. (Credit for idea: [bennuttall](https://github.com/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](https://github.com/Coal0) and [martinohanlon](https://github.com/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` – 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](https://github.com/scotty3785))
- Changed internal implementation of the Waffle so it should now be able to redraw more efficiently. (Credit: [scotty3785](https://github.com/scotty3785))
4 changes: 2 additions & 2 deletions docs-src/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ The aim of guizero is to make the process of creating simple GUIs quick, accessi

### Version

guizero is currently version 0.3.3
guizero is currently version 0.4

This is a pre-release version, so there may be bugs and features may change.
There may be bugs and features may change and be updated.
8 changes: 5 additions & 3 deletions docs-src/alerts.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ If `No` is pressed, an error box will be displayed
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.

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

Expand All @@ -89,7 +90,8 @@ You can use a `yesno` box to check whether someone really wants to exit your app

```python
from guizero import App, Text, yesno
# Ask user if they really want to close the window

# Ask the user if they really want to close the window
def do_this_on_close():
if yesno("Close", "Do you want to quit?"):
app.destroy()
Expand All @@ -98,7 +100,7 @@ app = App()

title = Text(app, text="blank app")

# When user tries to close the window, execute do_this_on_close()
# When the user tries to close the window, run the function do_this_on_close()
app.on_close(do_this_on_close)

app.display()
Expand Down
15 changes: 15 additions & 0 deletions docs-src/allwidgets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Common methods

These methods can be called upon any guizero widget.

| Method | Takes | Description |
| ------------- | --------- | -------------------------- |
| after(time, command) | time (int), command (function name) | Schedules a **single** call to `command` after `time` milliseconds. (To repeatedly call the same command, use `repeat()`) |
| repeat(time, command) | time (int), command (function name) | 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. |
| 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. |
| show() | - | Displays the widget |
100 changes: 45 additions & 55 deletions docs-src/app.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,80 @@
# App

(Extends the `Tk` class from `tkinter`)
(Contains a `tkinter.Tk` object)

### Purpose
The `App` object is the basis of all GUIs created using guizero. You can imagine it as a container, to which other widgets are added.
`__init__(self, title="guizero", width=500, height=500, layout="auto", bgcolor=None, bg=None)`

```
class guizero.App(title="GUIzero", height=500, width=500, layout="auto", bgcolor=None)
```
### 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](images/app.png)

### Documentation
### How do I make one?

Create an App object like this:
Create an `App` object like this:

```python
from guizero import App
app = App()
app.display()
```

**Parameters**
### Starting parameters

When creating an `App` object, you can specify the following parameters, all of which are optional. (More information about how to specify parameters can be found in the ['How to...'](./howto/) section.)
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 |
| --------- | --------- | ------- | ---------- | -------------------------|
| title | string | "GUIzero" | No | The title displayed in the bar at the top of the window. |
| bg | string | None | No | The background colour of the app window. Takes a RGB h ex colour (e.g. #0099ff) or a known colour string (e.g. "black"). |
| height | int | 500 | No | The height of the window in pixels. |
| width | int | 500 | No | The width of the window in pixels. |
| layout | string | "auto" | No | Whether widgets pack themselves (`"auto"`) or you specify their position on a grid (`"grid"`) |
| bgcolor | string | None | No | The background colour of the app window. Takes a RGB Hex colour (e.g. #0099ff) or a known colour string (e.g. "black"). |
| 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. |
| _bgcolor_ | _string_ | _None_ | _No_ | _Replaced by `bg` parameter_ |

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

**About the 'layout' parameter**
### Methods

The parameter `layout` allows you to specify whether the widgets in your app are placed automatically (`auto`), or whether you wish to position them yourself on a grid (`grid`). The default layout is `auto`.
You can call the following methods on an `App` object.

If you choose the `grid` layout, this means that when you create a widget you will need to pass the widget an extra parameter called `grid` which is a list containing `[x,y]` coordinates for where you want the widget to appear within the app, like this:
| Method | Takes | Returns | Description |
| ------------- | --------- | ---------- | -------------------------- |
| after(time, command) | time (int), command (function name) | - | 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 |
| 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. |
| focus() | - | - | Gives focus to the widget |
| on_close(command) | command (function name) | - | Calls the given function when the user tries to close the window. |
| repeat(time, command) | time (int), command (function name) | - | 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_title(title)_ | _title (string)_ | - | _Replaced by `title` property_ |
| _bgcolor_ | _bgcolor (string)_ | - | _Replaced by `bg` property_ |

```python
text = Text(app, text="Hello world", grid=[0,1])
```
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

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.
### Properties

### Methods summary
You can set and get the following properties:

You can call the following methods on your App object
| Method | Data type | Description |
| ------------- | ----------- | -------------------------- |
| bg | string | The background colour of the window |
| height | int | The height of the window |
| title | string | The title of the window |
| width | int | The width of the window |

| Method | Takes | Returns | Description |
| ------------- | --------- | ---------- | -------------------------- |
| 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. |
| set_title(title) | title (string) | - | Takes a string `title` and displays this in the top bar of the app window |
| on_close(command) | command (function name) | - | Calls the given function when the user tries to close the window. |
| destroy | - | - | Closes the app window. |
| bgcolor | bgcolor (string) | - | Changes the background colour of the window. Takes a RGB Hex colour (e.g. #0099ff) or a known colour string (e.g. "black"). |

Refer to a property as `<name of widget>.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**

You can 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.
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.

Then, at the end of the program you **MUST** tell the app object to begin the display loop.
At the end of the program you **MUST** tell the app object to begin the display loop.

```python
from guizero import App
Expand All @@ -78,30 +89,9 @@ You can change the title of the app object once it has been created like this:
```python
from guizero import App
app = App(title="My app", height=300, width=200)
app.set_title("A different title")
app.title = "A different title"
app.display()
```
This will display the app with the updated title:

![App title](images/app_set_title.png)

**Using grid layout**

You can lay components out in a grid and specify where they appear with grid layout.

![App title](images/keypad_windows.png)

```python
from guizero import App, PushButton
def do_nothing():
print("Nothing happened")

app = App(title="Keypad example", width=100, height=90, layout="grid")
button1 = PushButton(app, command=do_nothing, text="1", grid=[0,0])
button2 = PushButton(app, command=do_nothing, text="2", grid=[0,1])
button3 = PushButton(app, command=do_nothing, text="3", grid=[0,2])
button4 = PushButton(app, command=do_nothing, text="4", grid=[1,0])
button5 = PushButton(app, command=do_nothing, text="5", grid=[1,1])
button6 = PushButton(app, command=do_nothing, text="6", grid=[1,2])
app.display()
```
Loading

0 comments on commit 16f5761

Please sign in to comment.