0

I am new at programming and I am doing some experiment with this login screen. I want to create some "User" and "Password" combination that can close the project when I click the button "Enter". This should destroy the whole database in the future, but I think thats more like a pro-programmer issue.

For now it kinda works, but it doesn't close the project.

Any idea whats wrong? (I know it only checks password for now, but I would like to fix the button problem first and then check if user is ok too)

import tkinter as tk
from tkinter import *

root = Tk()
root.title("Login")
root.geometry("157x160")

def submit():

    name=name_var.get()
    password=passw_var.get()

    if  password == "delete":
        print("Closed")
        command=root.quit
    else:

            print('User: ' + name)
            print('Password: ' + password)

            name_var.set("")
            passw_var.set("")

name_var=tk.StringVar()
passw_var=tk.StringVar()

name_label = tk.Label(root, text = 'User', font=('calibre',10, 'bold'))

name_entry = tk.Entry(root,textvariable = name_var, font=('calibre',10,'normal'))

passw_label = tk.Label(root, text = 'Password', font = ('calibre',10,'bold'))

passw_entry=tk.Entry(root, textvariable = passw_var, font = ('calibre',10,'normal'), show="X")

sub_btn=tk.Button(root,text = 'Enter', command = submit)


name_label.place(x = 10, y = 10)
name_entry.place(x = 13, y =25)
passw_label.place(x = 10, y = 60)
passw_entry.place(x = 13, y = 75)
sub_btn.place(x = 48, y =120)


root.mainloop()
imxitiz
  • 3,920
  • 3
  • 9
  • 33
Ann
  • 3
  • 1

1 Answers1

0

You aren't calling quit function so, It isn't working for you. But Just use root.quit() or root.destroy() should also work.

And you're doing command= I am not sure why but just root.quit() will work, you don't have to do command=root.quit().

Learn more from here to know about .quit() and .destroy().

root.quit() causes mainloop to exit. Calling root.destroy() will destroy all the widgets and exit mainloop

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • I don't think you're using Python2 but you're importing `Tkinter` rather then `tkinter` also. I believe this is typo while posting question. – imxitiz Aug 22 '21 at 02:50