在tkinter中使用用户名和密码登录表单

时间:2019-11-24 08:19:57

标签: python database forms tkinter

我想显示一个包含用户名和密码的表单,在简单的情况下,我尝试打印输入的用户名和密码。

在我的代码中,当我按下“提交”按钮时,用户名和密码不会从其他功能中打印出来。

任何人都可以帮忙。 “用户名” “密码” 需要打印

def activation():
    activate = Tk()
    activate.title("Account Login")
    w = 600
    h = 400
    ws = activate.winfo_screenwidth()
    hs = activate.winfo_screenheight()
    x = (ws / 2) - (w / 2)
    y = (hs / 2) - (h / 2)
    activate.geometry("%dx%d+%d+%d" % (w, h, x, y))
    global username_entry
    global password_entry
    username_entry = StringVar()
    password_entry = StringVar()

    Label(activate,text='Activation Number').grid(row=1,column=1,sticky='we')
    Entry(activate, width=40, textvariable=username_entry).grid(row=1, column=2, columnspan=2)

    Label(activate,text='Password').grid(row=2,column=1,sticky='we')
    Entry(activate, width=40, show='*', textvariable=password_entry).grid(row=2,column=2,columnspan=2)

    remember_me=BooleanVar()
    Checkbutton(activate,text='Remember Me',variable=remember_me).grid(row=3, column=2)

    Button(activate,text='Submit',command=login_verify).grid(row=3,column=3)

def login_verify():
    username=username_entry.get()
    password=password_entry.get()
    print(username)
    print(password)
    print('1')

1 个答案:

答案 0 :(得分:0)

from tkinter import *
parent=Tk()
bullet = "\u2022" #specifies bullet character
widgetname = Entry(parent,show=bullet)#shows the character bullet
widgetname.pack()
def getPassword(event=None):
    value=widgetname.get()
    print("You entered",value)
btn=Button(parent,text="Submit",command=getPassword)
btn.pack()
parent.bind("<Return>",getPassword)
parent.mainloop()