为什么这个python Tkinter代码不会工作?

时间:2016-02-17 19:21:59

标签: python python-3.x tkinter

我刚刚开始编写这个tkinter程序,我发现错误。 这是错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\rhysj_000\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1549, in __call__
    return self.func(*args)
  File "G:\Login\Login v2.py", line 21, in check_password
    if (user,'=',password in line):
TypeError: 'in <string>' requires string as left operand, not Entry

try:
    import tkinter as tk
except ImportError:
    import Tkinter as tk
# from http://effbot.org/tkinterbook/entry.htm
failure_max = 3
def make_entry(parent, caption, width=None, **options):
    tk.Label(parent, text=caption).pack(side=tk.TOP)
    entry = tk.Entry(parent, **options)
    if width:
        entry.config(width=width)
    entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
    return entry
def enter(event):
    check_password()
def check_password(failures=[]):
    datafile = open('login\profile.passwords')
    for line in datafile:

        if (user,'=',password in line):
            root.destroy()
            print('Logged in')
            return
            failures.append(1)
            if sum(failures) >= failure_max:
                root.destroy()
                raise SystemExit('Unauthorized login attempt')
            else:
                root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))
root = tk.Tk()
root.wm_iconbitmap("Login icon.ico")
root.geometry('300x160')
root.title('Enter your information')
#frame for window margin
parent = tk.Frame(root, padx=10, pady=10)
parent.pack(fill=tk.BOTH, expand=True)
#entrys with not shown text
user = make_entry(parent, "User name:", 16, show='~')
password = make_entry(parent, "Password:", 16, show="*")
#button to attempt to login
b = tk.Button(parent, borderwidth=4, text="Login", width=10, pady=8,    command=check_password)
b.pack(side=tk.BOTTOM)
password.bind('<Return>', enter)
user.focus_set()
parent.mainloop()

0 个答案:

没有答案