tkinter: creating/attaching menubar to top level window

Richard Damon Richard at Damon-Family.org
Fri Jan 8 17:16:20 EST 2021


On 1/8/21 4:47 PM, Rich Shepard wrote:
> 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).
>
> Why am I getting an invalid syntax error here?
>
> TIA,
>
> Rich 


Because it is the wrong syntax.

It could be either:

self.menu = menubar

or

self['menu'] = menubar

-- 
Richard Damon



More information about the Python-list mailing list