sebp / PyGObject-Tutorial

Tutorial for using GTK+ 3 in Python
https://python-gtk-3-tutorial.readthedocs.io/
GNU Lesser General Public License v2.1
393 stars 161 forks source link

layout_listbox_example.py error #140

Closed lukegm closed 6 years ago

lukegm commented 6 years ago

The tutorial example examples/layout_listbox_example.py if run as written currently fails with the error:

 File "../PyGObject-Tutorial/examples/listbox_demo.py", line 87
    listbox_2.connect('row-activated', lambda widget, row: print(row.data))
                                                               ^
SyntaxError: invalid syntax

The above error occurs for both Python 2 & 3

$ python --version
Python 2.7.6

$ python3 --version
Python 3.4.3

riojano0 in: https://stackoverflow.com/questions/39278023/python-2-7-gtk-3-listbox-connect-print-active-row: Suggests replacing the 'print()' directive with the 'repr()' to make the example work.

I can confirm that the example layout_listbox_example.py works perfectly after the change.

Attached is a git patch for the change to the file. I've never created one before, so I don't know if it's any good, or helpful.

Thanks for all the effort that's gone in to creating and maintaining the tutorials. Props guys.

Cheers Luke

0001-layout_listbox_example.patch.txt

ailtonbsj commented 6 years ago

The function repr() didn't work for me. I'm using Lubuntu 18.04 LTS. I solved with:

def on_row_activated(listbox, row):
      print(row.data)
listbox_2.connect('row-activated', on_row_activated)