Reputation: 1
How can I change windows using buttons?
from appJar import gui
def press(btn):
def revision(rvs):
app = gui("Revision page", "500x200")
app.setBg("green")
app.setFont(18)
app.addLabel("title2", "Please select a topic you would like to rveise")
app.go()
def menu():
app = gui("Menu", "500x200")
app.setBg("green")
app.setFont(18)
app.addLabel("title1", "Menu")
app.addButtons(["Revision", "Quiz", "Progress"], press)
app.go()
menu()
Upvotes: 0
Views: 1139
Reputation: 273
You can't run two instances of appJar, instead, you need to create subWindows: http://appjar.info/pythonSubWindows/
So, using your current code:
from appJar import gui
def press(btn):
if btn == "Revision":
app.showSubWindow("Revision page")
app = gui("Menu", "500x200")
app.setBg("green")
app.setFont(18)
app.addLabel("title1", "Menu")
app.addButtons(["Revision", "Quiz", "Progress"], press)
app.startSubWindow("Revision page", "500x200")
app.setBg("green")
app.setFont(18)
app.addLabel("title2", "Please select a topic you would like to rveise")
app.stopSubWindow()
app.go()
It's easier to visualise if you use contextManagers:
from appJar import gui
def press(btn):
app.showSubWindow(btn + " page")
with gui("Menu", "500x200") as app:
app.setBg("green")
app.setFont(18)
app.addLabel("title1", "Menu")
app.addButtons(["Revision", "Quiz", "Progress"], press)
with app.subWindow("Revision page", size="500x200"):
app.addLabel("revTitle", "Please select a topic you would like to rveise")
with app.subWindow("Quiz page", size="500x200"):
app.addLabel("quizTitle", "Quiz Page")
with app.subWindow("Progress page", size="500x200"):
app.addLabel("progTitle", "Check Progress")
And, in the latest release, a lot of the properties can be set as parameters and there are new functions for adding widgets:
from appJar import gui
def press(btn):
app.showSubWindow(btn + " page")
with gui("Menu", "500x200", bg='green', font={'size':18}) as app:
app.label("Menu")
app.buttons(["Revision", "Quiz", "Progress"], press)
with app.subWindow("Revision page", size="500x200", bg='red'):
app.label("Please select a topic you would like to rveise")
with app.subWindow("Quiz page", size="500x200", bg='blue'):
app.label("Quiz Page")
with app.subWindow("Progress page", size="500x200", bg='orange'):
app.label("Check Progress")
Upvotes: 1