Am 08.01.21 um 22:47 schrieb Rich Shepard:
I'm using Chapter 9 in Mark Roseman's "Modern Tkinter for Busy Python
Developers" to learn how to write a top level menu. MWE code is attached.

Python3 tells me there's invalid syntax on line 42:
     self.['menu'] = menubar # attach it to the top level window
          ^
yet that's the syntax he prints on page 84 (and has in the book's code
supplement).

It is a simple typo, remove the dot.

        self['menu'] = menubar

It will then stop at the add_cascade, fix it like this:

 menubar.add_cascade(menu=self.menu_file, label='File')

and then it works,

Why am I getting an invalid syntax error here?

Because the dot would indicate the access of an attribute. but no name follows. What it does here, instead, is indexing - the correct line is similar to setting a dict entry.

        Christian
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to