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 –