如何在tkinter python中创建一组用户名和密码
问题描述:
在tk inter中,他们将使用特定的用户名和密码打开特定的文件,如果管理员登录他将被带到管理员页面。如何在tkinter python中创建一组用户名和密码
from Tkinter import *
root = Tk()
w = Label(root, text="LiftServer(Sign-in)")
w.pack()
e1 = Label(root, text="******************************")
e1.pack()
w1 = Label(root, text="Username")
w1.pack()
e = Entry(root)
e.pack()
w2 = Label(root, text="Password")
w2.pack()
e1 = Entry(root)
e1.pack()
toolbar = Frame(root)
b = Button(toolbar, text="Enter", width=9)
b.pack(side=LEFT, padx=2, pady=2)
b = Button(toolbar, text="Cancel", width=9)
b.pack(side=LEFT, padx=2, pady=2)
def callback():
execfile("signup.txt")
b = Button(toolbar, text="Sign-Up", command=callback, width=9)
b.pack(side=LEFT, padx=2, pady=2)
toolbar.pack(side=TOP, fill=X)
mainloop()
答
不完全知道你问,但我认为这个答案吧..
def callback():
if w.get() == "Bob" and w2.get() == "password":
openfile('file1')
else:
openfile('file2')
异常在Tkinter的回调 回溯(最近通话最后一个): 文件“C:\ Python27 \的DLL \ lib \ tk \ Tkinter.py“,行1470,在__call__中 返回self.func(* args) 文件”C:/ Documents and Settings/1209131/Desktop/ftg“,第26行,回调 if w1.GetValue()==“Bob”和w2.GetValue()==“password”: AttributeError:标签实例没有at 'GetValue'看起来像得到的价值是错的 – 2013-05-13 16:00:29
多数民众赞成在我说的...你需要使用任何方法你用“GetValue”的文本框(实际上2秒的谷歌搜索告诉我这只是'get()'而不是'GetValue()'... – 2013-05-13 16:28:22