-2

I have built a login system using Tkinter and Sqlite3 for Python and I need to move on to another section of code once the login flow is complete. At the point in the 'test' function where I've added a comment, I need a separate python file (eg somefile.py) to run its code. How is best to do this? Your help is appreciated! Code below:

from tkinter import *
import Check_credentials as check
import New_user_screen as create

def test():
username = user.get()           
password = pword.get()
global valid
valid = False
valid=check.check_user(username,password)
print(valid)
if valid == True:                                
    login.destroy()
    'launch main program'  #Here is where i need the next section of the program to be run but ideally not as another function in this proram                   
    print('Incorrect login getails\nPlease try again!')


def screen():
global login
login = Tk()               
login.title('User Login')
login.geometry('300x180')
login.configure(background = 'white')
global user
global pword


message = Label(login,
                text = 'Please enter username and password below',   
                bg='white')
message.pack()


label1 = Label(login,
               text = 'Username',       
               bg='white')
label1.place(x=0,y=50)


user = Entry(login)           
user.place(x=100,y=50)



label2 = Label(login,
               text = 'Password',       
               bg='white')
label2.place(x=0,y=90)

pword = Entry(login)
pword.place(x=100,y=90)           


confirm = Button(login,
                 text='Sign In',             
                 fg='white',
                 bg='blue',
                 command = test)
confirm.place(x=50,y=130)

new = Button(login,
             text='New User',           
             fg='white',               
             bg='blue',
             command = create.screen)
new.place(x=120,y=130)
  • You need to be more clear on expected and actual output. – matszwecja Apr 05 '22 at 10:32
  • You probably need something like goto, read this https://stackoverflow.com/questions/438844/is-there-a-label-goto-in-python – FLAK-ZOSO Apr 05 '22 at 10:33
  • @FLAK-ZOSO does the goto work for separate files though? – liam cassidy Apr 05 '22 at 10:59
  • If you read the answers, in Python the goto doesn't even work on the single file, but no, I've never seen a goto working across different files. Why don't you use functions in this case? – FLAK-ZOSO Apr 05 '22 at 11:01
  • The reason I don't want to use functions is because the file i need to run next is my 'main menu' which has lots of function calls off of it. I feel it will be simpler if i can have that file as a standalone, rather than calling it as a function. If there's no other sensible option though ill just have to go with it. – liam cassidy Apr 05 '22 at 11:09
  • I think you will have – FLAK-ZOSO Apr 05 '22 at 11:13
  • Did you try `import somefile`? – acw1668 Apr 06 '22 at 01:42

1 Answers1

0

When the login is valid, it will go to the the function greeting in the class Main

from tkinter import *
import Check_credentials as check
import New_user_screen as create


class Login:
    def test():
        username = user.get()           
        password = pword.get()
        global valid
        valid = False
        valid=check.check_user(username,password)
        print(valid)
        if valid == True:                                
            login.destroy()
            Main.greeting()  #Here is where i need the next section of the program to be run but ideally not as another function in this proram                   


    def screen():
        global login
        login = Tk()               
        login.title('User Login')
        login.geometry('300x180')
        login.configure(background = 'white')
        global user
        global pword


    message = Label(login,
                    text = 'Please enter username and password below',   
                    bg='white')
    message.pack()


    label1 = Label(login,
                text = 'Username',       
                bg='white')
    label1.place(x=0,y=50)


    user = Entry(login)           
    user.place(x=100,y=50)



    label2 = Label(login,
                text = 'Password',       
                bg='white')
    label2.place(x=0,y=90)

    pword = Entry(login)
    pword.place(x=100,y=90)           


    confirm = Button(login,
                    text='Sign In',             
                    fg='white',
                    bg='blue',
                    command = test)
    confirm.place(x=50,y=130)

    new = Button(login,
                text='New User',           
                fg='white',               
                bg='blue',
                command = create.screen)
    new.place(x=120,y=130)

class Main:
    def greeting():
        print("You Have Logged In Successfully")