Tkinter and SQlite project

Question:

from tkinter import *
from database import *

def Control_():
    var1 = NameE.get()
    var2 = LastnameE.get()
    var3 = UsernameE.get()
    var4 = PasswordE.get()
    search = KullaniciAra(var3)
    if search == None:
        kullanici_ekle(var1,var2,var3,var4)
        Login_Page()
    else:
        ErrorLabel = Label(win,text="This username is taken.")
        ErrorLabel.grid(row=8,column=1)

def Login_Page():
    def on_login():
        var3 = UsernameE2.get()
        var4 = PasswordE2.get()
        search2 = KullaniciAra(var3)
        if search2 == var4:
            print("Done!")
    win.destroy()

    new_win = Tk()
    new_win.title("T Messenger L")
    new_win.geometry("200x200")

    UsernameL2 = Label(new_win,text="Username",fg="black",bg="lightgray")
    UsernameL2.grid(row=0,column=0)
    UsernameE2 = Entry()
    UsernameE2.grid(row=0,column=1)

    PasswordL2 = Label(new_win,text="Password",fg="black",bg="lightgray")
    PasswordL2.grid(row=1,column=0)
    PasswordE2 = Entry()
    PasswordE2.grid(row=1,column=1)

    Button2 = Button(new_win,text="Login",command=on_login)
    Button2.grid(row=2,column=1)

    new_win.mainloop()

Tablo_olustur()

win = Tk()
win.title("T Messenger R")
win.geometry("200x200")

NameL = Label(win,text="Name",fg="black",bg="lightgray")
NameL.grid(row=1,column=0)
NameE = Entry()
NameE.grid(row=1,column=1)

LastnameL = Label(win,text="Lastname",fg="black",bg="lightgray")
LastnameL.grid(row=2,column=0)
LastnameE = Entry()
LastnameE.grid(row=2,column=1)

UsernameL = Label(win,text="Username",fg="black",bg="lightgray")
UsernameL.grid(row=3,column=0)
UsernameE = Entry()
UsernameE.grid(row=3,column=1)

PasswordL = Label(win,text="Password",fg="black",bg="lightgray")
PasswordL.grid(row=4,column=0)
PasswordE = Entry()
PasswordE.grid(row=4,column=1)

theLabel = Label(win,text="Login here",fg="blue",cursor="hand2",font=("TkDefaultFont",12,"underline"))
theLabel.grid(row=5,column=1)
theLabel.bind("<Button-1>", lambda event: Login_Page())

Button1 = Button(win,text="Register",command=Control_)
Button1.grid(row=6,column=1)

win.mainloop()

I wanted to make "login here" text with .bind() it worked as I want, it opened Login_Page() then even If I enter correct username and password when I click "Login" button nothing happens. What I want is "When ‘login’ button clicked and if username and password on my database and true open new page" and the new page name will be Vote_Page() cause user will choose like Find user, Update password, Delete acc etc

Asked By: xDevsMC

||

Answers:

When writing a dialog box, you should use a Toplevel window as its base, not Tk. There should onle be one Tk instance in your program.

The implementation of FileDialog in cpython/filedialog.py is a nice example of how to implement a dialog in a class.

Answered By: Roland Smith
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.