Since it imports tkinter with *, ugh, but that's another story, the functions are probably used for controls without inputs (like simple buttons).
The first immediately obvious improvement is deduplicating and outsourcing all logic into a helper function chosetag(tag) and just calling the helper with the corresponding string.
The second improvement, which a lot of beginners don't realize, is the fact that they can skip making special functions for every button by just using a lambda expression in the parameters for their buttons. So instead of action=chosetagComedy you can just use action= lambda : chosetag('Comedy')
If you do that, it would assign action to the result of chosetag. It would execute it. The lambda wraps the chosetag call into another function, so that it can be used as a callback.
63
u/RoLoLoLoLo Apr 24 '21
Since it imports tkinter with *, ugh, but that's another story, the functions are probably used for controls without inputs (like simple buttons).
The first immediately obvious improvement is deduplicating and outsourcing all logic into a helper function
chosetag(tag)and just calling the helper with the corresponding string.The second improvement, which a lot of beginners don't realize, is the fact that they can skip making special functions for every button by just using a lambda expression in the parameters for their buttons. So instead of
action=chosetagComedyyou can just useaction= lambda : chosetag('Comedy')