0

I want to display a form with a username and password, and in simple case I tried to print the entered username and password.

In my code, when I pressed the submit button the username and password are not printed from the other function.

Can anyone please help with it. The 'username' and 'password' needs to be printed.

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')
Abanish Tiwari
  • 167
  • 1
  • 2
  • 14
  • The username and password are printed as " " i.e. just a new line. Why the value is not printed? – Abanish Tiwari Nov 24 '19 at 08:30
  • I assume you use **multiple `Tk()`**, read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) – stovfl Nov 24 '19 at 10:26
  • @stovfl Thank you. I did not know that (beginner). Again, thank you for your help. – Abanish Tiwari Nov 24 '19 at 10:42

1 Answers1

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()