On 3/9/23 00:13, Thomas Passin wrote:


lol.. 'us'..

So.. to give an example from your own code:

but_play = Tk.Button(_frame, text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT)

Can be written as:

b = Tk.Button(master=_frame)
b.config(text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT)

.config() is just a way of adding/modifying most of the same initialization arguments after the instantiation of the object.

tkinter objects are flexible by design, You can also do
b["text"] = "adsfa"
b["command"] = lambda: (a,b,c,d)

I could also rewrite the original example with the exact same result:
b = tk.Button(
    master=main,
    text="Enable",
    command=lambda: (
        e1.config(state="normal"),
        e2.config(state="normal"),
        e3.config(state="normal")
    )
)
b.pack()

b is not changing states at any point. Nothing "happens" to state when .config() is called. b does nothing without a command= configured. .config() is binding the button press event via command= to a call so than an action can occur on button press. There is no 'instead' of b.config() (unless of course using one of the equivalent examples above to do the exact same thing)

The disconnect is not in the not understanding of my code, it's in the not understanding of .config(). (which is no big deal, I forgot what a file buffer was just this week, lol)

So, as far as the examples, they are simplified abstract psuedo-like-code illustrations to accompany the ask of and open ended question regarding a programming practice.

(I did forgot to include main.mainloop() at the end of each one, as I was using python -i when I quickly wrote them)

example 1 described:
A button press does sequence of actions against widgets, i.e. I have 3 disabled widgets, I press a button, now in sequence all 3 are enabled so I can type in them. Without a lambda tuple sequence this requires a def and an another lambda.

example 2 described:
dict with an attribute assigned to a label (you can't assign directly to external variables within a lambda, but you can call something with a method like .update(), which why would that be considered any different than any other state changing call?) Then lambda assigned to a label and called to start it up, recursively performs an update to said widget every 1 second. There are several ways to do this without a lambda tuple sequence, none as concise.

The 'what I am trying to do' is ask a question regarding opinions and practices on issuing a sequence of actions within a lambda via a tuple (since the common practice approaches against it - mainly with tkinter - feel more convoluted), and in doing so leaving it open ended to get a feel on what opinions are, and to see if any opinions influence mine.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to