Reputation: 8061
I want to show a login screen. Once login is successful, I want to show a window with a button. If I click on the button a file picker should open.
With my code, what happens is that after logging in correctly, the file picker opens directly, instead of, when a button is clicked. If file picker is closed, main window and another window with the button is shown. What is wrong with my code? How can I fix this?
This is my code:
from appJar import gui
app = gui()
def AuthenticationDetails(user, passw):
if user=="myuser" and passw=="mypass":
return True
else:
return False
def press(button):
usr = app.getEntry("Username")
pwd = app.getEntry("Password")
print("User:", usr, "Pass:", pwd)
if AuthenticationDetails(usr, pwd):
Success()
else:
app.errorBox("Failed login", "Invalid username or password")
def Success():
print("Successfully logged in")
def login(btn):
# app.hideSubWindow("Login")
app.showSubWindow("Main", hide=True)
app.buttons(["Choose file"], [choosefile(app)])
# app.addButton("Choose File", choosefile(app))
app.show()
def choosefile(app):
print("Opening Choose file")
app.openBox(title="Choose P1 form pdf file", dirName=None, fileTypes=None, asFile=False, parent="Main")
app.startSubWindow("Login")
app.label("Enter login details", bg='blue', fg='white')
app.entry("Username", label=True, focus=True)
app.entry("Password", label=True, secret=True)
app.buttons(["Submit", "Cancel"], [login, app.stop])
app.stopSubWindow()
app.startSubWindow("Main", title="ESI Superspecialty Reference Helper v1.0")
app.label("Your login was successful", bg='blue', fg='white')
app.setSize("400x200")
app.setBg("blue")
app.setFg("white")
app.stopSubWindow()
app.go(startWindow="Login")
Upvotes: 1
Views: 48
Reputation: 273
Your login()
function is calling the chooseFile()
function, rather than passing it as a callback argument.
Get rid of the app
parameter in the chooseFile()
function, then don't include any brackets or an argument when you assign chooseFile
to the button.
Upvotes: 1