lawsie / guizero

A Python 3 library to allow learners to quickly and easily create GUIs.
https://lawsie.github.io/guizero
BSD 3-Clause "New" or "Revised" License
406 stars 81 forks source link

Example in tutorial raises error #492

Open Thot-Htp opened 11 months ago

Thot-Htp commented 11 months ago

Describe the bug Trying to concatenate a string with event_data.widget with the + operator, as in the example: print("widget clicked = " + event_data.widget)

raises the error: print("widget clicked = " + event_data.widget) TypeError: can only concatenate str (not "App") to str

To Reproduce

  1. Go to https://lawsie.github.io/guizero/events/'
  2. Implement the following example (for example with widget = App() ) from the page:
from guizero import App

def clicked(event_data):
    print("widget clicked = " + event_data.widget)
    print("mouse position = " + event_data.x + "." + event_data.y)

app = App()
app.when_clicked = clicked

app.display()
  1. See error

Expected behavior The output: widget clicked = [App] object mouse position = 26 . 35

System information:

Additional context Replacing '+' with ',' ('plus' with 'comma') solves the problem, like so:

from guizero import App

def clicked(event_data):
    print("widget clicked = " , event_data.widget)
    print("mouse position = " , event_data.x , "." ,  event_data.y)

app = App()
app.when_clicked = clicked

app.display()
lawsie commented 6 months ago

Thanks @Thot-Htp - have added your change on dev