Tkinter menu item underline syntax [RESOLVED]

Terry Reedy tjreedy at udel.edu
Wed Jan 6 20:44:45 EST 2021


On 1/6/2021 4:17 PM, Terry Reedy wrote:
> On 1/6/2021 4:03 PM, Rich Shepard wrote:
>> On Thu, 7 Jan 2021, Chris Angelico wrote:
>>
>>> Are you sure that this works? It's syntactically valid, but I don't
>>> think it means what you think it does.
>>
>> ChrisA,
>>
>> I'm always open to learning. There's no error generated ... yet the
>> application doesn' open so it's time to run it through pdb.
> 
> See my response, sent an hour ago, for how to use 'underline.

Reposting:

'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