I am trying to call a set of subroutines I created which use arguments from other subroutines. For example, the variable 'username' should be able to be passed into 'db_username_searcher'.
def signer():
def login():
username = entry_user.get()
password = entry_user.get()
if username in admin_array:
admin_pass = 'pass'
return username, password, admin_pass
win = tkinter.Tk()
win.title('Sign In')
win.geometry('800x800')
lbl_user = tkinter.Label(win, text='Username ')
entry_user = tkinter.Entry(win)
lbl_pwd = tkinter.Label(win, text='Password ')
entry_pwd = tkinter.Entry(win, show='x')
lbl_output = tkinter.Label(win)
btn_signin = tkinter.Button(win, text='Sign in', command=login)
lbl_user.pack()
entry_user.pack()
lbl_pwd.pack()
entry_pwd.pack()
lbl_output.pack()
btn_signin.pack()
entry_user.focus_set()
win.mainloop()
This is the code where 'username' is assigned and returned:
def db_username_sercher(username, password):
conn = sqlite3.connect('passwordDbase.db')
c = conn.cursor()
c.execute("SELECT * FROM passwordDb WHERE employee_username=?", (username, ))
r = c.fetchone()
if r:
message = 'correct'
else:
message = ' '
if message == 'correct':
dbpassword = c.execute("SELECT employee_password FROM passwordDb WHERE employee_username=?", (username, ))
if dbpassword == password:
message = 'correct'
else:
message = ' '
conn.commit()
c.close()
conn.close()
return message
When I try to call the two functions, I am not aware of how to deal with the arguments:
signer()
db_username_searcher(username, password)
"unresolved reference 'password' "
How do I call this properly?, Thanks in advance.
There's two ways you could do this.
One: You need to add a line of code before the call to db_username_earcher()
where you catch
all of the variables return
ed by signer()
into a list
/multiple variables. Then, you could pass username by using the list index or the variable you assigned to catch username.
Two: You could use global
variables, and your signer()
function could simply overwrite username, so that you can pass username in without any difficulties.
EDIT (in response to comments):
To catch
the variables, you could do a, b, c = signer()
, where a
would contain the value of username
.
About the list method, I meant that you need to return
a list instead of three variables, and then you can directly reference username
by using your_caught_list[0]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.