I'm coding a Remember Username feature in Python with a checkbox for my application. Now I need to be able to get the status of the checkbox because when the user exits my application and then opens it again, while the username will still be remembered, the checkbox will look unticked. So I think I need to find a way to see if the checkbox is already selected from last time or not, and set REMEMBER_USERNAME to True or False accordingly.
I have not found an easy way to do so with the way my code is written.
GUI part, it's a bit too long so I've pasted it in a pastebin here https://pastebin.com/j8FEdA36
main.py
def RememberUsername(self):
REMEMBER_USERNAME = True
self.checkBox = ui.CheckBox()
self.checkBox.SetParent(self)
self.checkBox.SetEvent(ui.__mem_func__(self.SaveUsername), "ON_CHECK", True)
self.checkBox.SetEvent(ui.__mem_func__(self.SaveUsername), "ON_UNCHECK", False)
self.checkBox.SetCheckStatus(REMEMBER_USERNAME)
self.checkBox.SetTextInfo("Remember username")
self.checkBox.Show()
def SaveUsername(self, checkType, autoFlag):
if REMEMBER_USERNAME = True:
# remember the username
else:
# forget the username
Currently it's being done manually, e.g. when I define REMEMBER_USERNAME = True, the checkbox will always be ticked, when defined as False, the checkbox will be unticked, and so on.
I apologize if I sound all over the place, please let me know If you need any further clarification.
Aucun commentaire:
Enregistrer un commentaire