Python Forum
[Tkinter] Programmatically creating buttons that remember their positions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Programmatically creating buttons that remember their positions
#6
(Jun-21-2023, 08:20 PM)Clunk_Head Wrote: did my first code create one lambda that was referenced by all buttons, or did it crate a lambda for each function that all referenced the same variables?
It created a lambda for each button that all referenced to the same variables as in this example
>>> def func():                                                                             
...     var = 3                               
...     spam = lambda: var        
...     var = 4                               
...     ham = lambda: var                                                                   
...     return spam, ham                                                                    
...                                                                                         
>>> f, g = func()
>>> f is g
False
>>> f.__closure__
(<cell at 0x7f3135163160: int object at 0x7f3135374150>,)
>>> g.__closure__
(<cell at 0x7f3135163160: int object at 0x7f3135374150>,)
>>> f.__closure__[0].cell_contents             
4
>>> g.__closure__[0].cell_contents             
4
>>>   
Clunk_Head likes this post
Reply


Messages In This Thread
RE: Programmatically creating buttons that remember their positions - by Gribouillis - Jun-22-2023, 06:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] How to add conversions and fix button positions. javesike1262 7 3,058 Jan-31-2021, 04:39 PM
Last Post: deanhystad
  Creating a frame with 4 command buttons Heyjoe 5 2,614 Aug-21-2020, 03:16 PM
Last Post: deanhystad
  GUI Tkinter Widget Positions punksnotdead 3 3,065 Jun-12-2019, 06:06 PM
Last Post: Yoriz
  A little idea to remember wxPython classes Sebastian_Adil 0 2,369 Mar-26-2018, 10:23 PM
Last Post: Sebastian_Adil
  Fill out form on webpage and post request programmatically ian 2 3,698 Jul-18-2017, 03:12 PM
Last Post: ian

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020