本文整理汇总了Python中gui.Gui.display_passw方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.display_passw方法的具体用法?Python Gui.display_passw怎么用?Python Gui.display_passw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gui.Gui
的用法示例。
在下文中一共展示了Gui.display_passw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import display_passw [as 别名]
class Engine:
alphas = ["a", "a1", "a1A", "a1A!"]
alpha = 0
training = 0
ready = 0
def __init__(self):
self.option = "amount"
self.options = {"amount":(5,0), "uptime":(20,0), "delay":(20,0), "alphas":self.alphas[self.alpha]}
self.gui = Gui(self.key_event_handler)
apply(self.gui.display_option, (), self.options)
self.rnd = Random()
def run(self):
self.gui.run()
def train(self):
if self.training:
return
self.training = 1
self.ready = 0
self.user_input = []
self.passw = []
i = 0
var = self.options["amount"][1]
len = self.options["amount"][0] + self.rnd.randint(-1*var, var)
if len < 1:
len = 1
while i < len:
char = self.rnd.randint(33,126)
if self.alpha!=3:
if char in range(33,48) or char in range(58,65) or char in range(91,97) or char in range(123,127): # special characters
continue
if self.alpha!=2:
if char in range(65,91): #A-Z
continue
if self.alpha!=1:
if char in range(48,58): #0-9
continue
if not self.alpha in range(4):
raise "train: illigal value for alpha: %d" %self.alpha
self.passw.append(chr(char))
i += 1
self.callback(0,0)
def callback(self, *args):
if args[1] == 0:
if args[0] < self.passw.__len__():
self.gui.display_passw(self.passw, args[0], args[0]+1)
upt, var = self.options["uptime"]
total = upt + self.rnd.randint(-1*var, var)
self.gui.tk_callback(total*10, self.callback, args[0], 1)
else:
self.ready = 1
else:
self.gui.display_passw(self.passw,0,0)
delay, var = self.options["delay"]
total = delay + self.rnd.randint(-1*var, var)
self.gui.tk_callback(total*10, self.callback, args[0]+1, 0)
def user_completed(self):
mistakes = self.passw.__len__() - self.user_input.__len__()
for i in range(self.user_input.__len__()):
if self.passw.__len__() <= i:
mistakes += 1
else:
if ord(self.user_input[i])!= ord(self.passw[i]):
mistakes += 1
user = join(self.user_input,"")
pw = join(self.passw, "")
show = join((pw, user, str(mistakes)))
self.gui.display_passw(show, 0, show.__len__())
self.gui.newline()
self.training = 0
self.ready = 0
def key_event_handler(self, event):
k = event.keysym
if k in ("F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Up", "Down", "Left", "Right"):
self.handle_options(k)
else:
self.handle_user_input(k)
def handle_options(self, k):
if k == "F2":
self.option = "amount"
elif k == "F3":
self.option = "uptime"
elif k == "F4":
self.option = "delay"
elif k == "F5":
self.option = "alphas"
elif k in ("Up", "Down", "Left", "Right"):
if self.option in ("amount", "uptime", "delay"):
a,b = self.options[self.option]
#.........这里部分代码省略.........