Tkinter menu item underline syntax [RESOLVED]

Peter Otten __peter__ at web.de
Thu Jan 7 05:36:51 EST 2021


On 06/01/2021 22:03, Grant Edwards wrote:

> 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.
> 
> Huh?

You're completely right:

 >>> class C:
	def __getitem__(self, index): return index

	
 >>> c = C()
 >>> underline = 42
 >>> c["foo", underline: 0]
('foo', slice(42, 0, None))

The OP's code will most certainly fail at runtime ;)





More information about the Python-list mailing list