I have this code I'd like to condense if possible:
def ForgetPassword():
""" Clear sudo password for extreme caution """
global SUDO_PASSWORD
SUDO_PASSWORD = None
self.tools_menu.add_command(label="Forget sudo password", underline=0,
font=g.FONT, command=ForgetPassword, state=tk.DISABLED)
Rather than using command=ForgetPassword
, is it possible for something like command=SUDO_PASSWORD=NONE
?
command=
option is a function to be called later, and you have no option other than a fulldef
here because alambda
cannot assign to a global variable.def
for this but there are workarounds. A terrible approach would be to makeSUDO_PASSWORD
into a mutable object like a list containing only 1 string. Then you can do something likecommand=SUDO_PASSWORD_LIST.clear
sincelist
objects have aclear
method.SUDO_PASSWORD
being a list would allow you to put the expiry time as the second value.