0
以下是我的密码检查程序。如何使标记为为全球性的,以便我可以从另一个文件访问它? (即通过在另一个文件中使用“from this_file_name导入标志”)Python从不同的文件访问全局变量
另外,如何屏蔽输入?
import wx, os, re
class MyClass(wx.Frame):
def __init__(self, parent=None, id=-1):
box1 = wx.TextEntryDialog(None, 'Enter a password:')
if box1.ShowModal() == wx.ID_OK:
answer1 = box1.GetValue()
if re.search(r'\d', answer1) and re.search(r'[A-Z]', answer1) and re.search(r'[a-z]', answer1) and len(answer1) > 6:
box2 = wx.MessageBox('Your Password is Strong.')
global flag
flag = 0
else:
box2 = wx.MessageBox('Your Password is weak. It must contain atleast one uppercase, one lowercase letter and one '
'digit.')
global flag
flag = 1
if __name__=='__main__':
app = wx.App(0)
frame = MyClass()
frame.Show()
app.MainLoop()
参见:HTTP:// stackoverflow.com/questions/21891411/global-variable-between-frames-in-wxpython –