Tkinter menu item underline syntax

Terry Reedy tjreedy at udel.edu
Wed Jan 6 15:21:06 EST 2021


On 1/6/2021 1:32 PM, Rich Shepard wrote:
> My application's menu has lines like this:
>          file_menu.add_command(
>              label = 'New',
>              command = self.callbacks['file->new', underline 0],
>              accelerator = 'Ctrl+N'
>          )

'underline' has nothing to do with looking up the command in 
self.callbacks.  It is a keyword parameter for the add_command method, 
and is handled like all other values passed by name, and as you did for 
the other arguments

           file_menu.add_command(
               label='New',
               underline=0,
               command=self.callbacks['file->new],
               accelerator='Ctrl+N'
           )

Note: PEP 8 style is no spaces around '=' used for keyword  arguments. 
Here is an example from idlelib.editor, 978.

     menu.add_command(label=ulchars[i] + " " + file_name,
                      command=callback,
                      underline=0)


-- 
Terry Jan Reedy




More information about the Python-list mailing list