On Thu, Jan 7, 2021 at 9:22 AM Grant Edwards <[email protected]> wrote:
>
> On 2021-01-06, Rich Shepard <[email protected]> wrote:
> > On Wed, 6 Jan 2021, [email protected] wrote:
> >
> >> For the sake of future generations who may run into this issue, can you
> >> post the complete, correct call to file_menu.add_command?
> >
> > This is the working version of the stanza I initially posted:
> >
> > file_menu.add_command(
> > label = 'New',
> > command = self.callbacks['file->new', underline: 0],
> > accelerator = 'Ctrl+N'
> > )
>
> I'm completely baffled by that. Can somebody explain how this
> expression is evaluated?
>
> self.callbacks['file->new', underline: 0]
>
> It appears that the dict callbacks is being accessed with the key of
> a tuple comprising a string and a slice.
>
Heh, you had to try it to make sure it was valid? Me too. Here's how
it's parsed:
self.callbacks[ # this bit's non-controversial
'file->new' # string literal
, # make tuple
underline: 0 # slice(underline, 0, None)
]
So it takes the name "underline", whatever that is, and it assumes you
want a slice from underline to zero. That's all the second dimension
of the indexing, where the first is a simple string literal.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list