1

I am creatig a log-in system in a tkinter.notebook tab and I need to update the tab to enter the actual program after the user enters its userName and its password and click a button

Im using python 3.7 and the lastest tkinter version

import tkinter as tk
from tkinter import ttk

class MainApp(ttk.Frame):
    def __init__(self,main_window):
        super().__init__(main_window)
        main_window.title("User")

        self.notebook = ttk.Notebook(self,height=600,width=500)

        self.reservation_page=reservaiones(self.notebook)
        self.notebook.add(self.reservation_page,text="Reservations",padding=10)

        self.notebook.pack(padx=10, pady=10)
        self.pack()

class reservaiones(ttk.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.userName=tk.Entry(self)
        self.userName.place(x=100,y=50)
        self.userNameLabel=tk.Label(self,text="User Name")
        self.userNameLabel.place(x=20, y =50)

        self.password= tk.Entry(self)
        self.password.place(x=100,y=100)
        self.userNameLabel = tk.Label(self, text="Password")
        self.userNameLabel.place(x=20, y=100)

        self.logIn=tk.Button(self,text="Log In",command=self.getLoginInfo)
        self.logIn.place(x=100,y=200)

    def getLoginInfo(self):
        userName=self.userName.get()
        password=self.password.get()
        # Change this for the actual user list
        logInList=[['1','a','0'],['2','b','1'],['3','c','0']]

        for user in logInList:
            if userName==user[0]:
                if password==user[1] and user[2]!='1':
                    continue
                elif password==user[1] and user[2]=='1':
                    self.migration=tk.Label(self,text="User with migration issues")
                    self.migration.place(x=50,y=150)
                else:
                    self.wrongUserPassword = tk.Label(self, text="Access denied, wrong User Name or Password")
                    self.wrongUserPassword.place(x=2, y=150)
            else:
                self.wrongUserPassword = tk.Label(self, text="Access denied, wrong User Name or Password")
                self.wrongUserPassword.place(x=2, y=150)
                break

        self.userName.delete(0,tk.END)
        self.password.delete(0,tk.END)

This is the tab so far, the idea is that when the user enters 1 as user-name and a as password the tab updates itself

5
  • There's no notebook tab in your code. Commented May 21, 2019 at 2:10
  • Yeah sorry, i forgot to include it, now there is :) Commented May 21, 2019 at 2:13
  • What do you mean by I need to update the tab to enter the actual program, do you have code for your actual program Commented May 21, 2019 at 2:33
  • Like when you login into Facebook, you enter your username and password and then click login and then it enters your account, I need to do that but in a notebook tab like showing other things once the login is complete Commented May 21, 2019 at 2:53
  • I see that your MainApp inherits from Tk but it also has a master. Are you using multiple instances of Tk? Commented May 21, 2019 at 3:15

1 Answer 1

1

I suggest you to change your method getLoginInfo to something like this:

def getLoginInfo(self):
    login_success=False
    userName=self.userName.get()
    password=self.password.get()
    # Change this for the actual user list
    logInList=[['1','a','0'],['2','b','1'],['3','c','0']]

    for user in logInList:
        if userName==user[0]:
            if password==user[1] and user[2]!='1':
                login_success=True
                break
            elif password==user[1] and user[2]=='1':
                self.migration=tk.Label(self,text="User with migration issues")
                self.migration.place(x=50,y=150)
            else:
                self.wrongUserPassword = tk.Label(self, text="Access denied, wrong User Name or Password")
                self.wrongUserPassword.place(x=2, y=150)
        else:
            self.wrongUserPassword = tk.Label(self, text="Access denied, wrong User Name or Password")
            self.wrongUserPassword.place(x=2, y=150)
            break
    if login_success:
        # Remove all the current widgets before drawing new
        for child in self.winfo_children():
            child.destroy()
        self.call_next_function_to_draw_actual_program()
Sign up to request clarification or add additional context in comments.

1 Comment

When i remove the widgets it throws me an error, it doesn't has any effect in the program, but, how can I solve this error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.