如何使用按钮更改窗口?
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()
答案 0 :(得分:0)
您无法运行两个appJar实例,而是需要创建子窗口:http://appjar.info/pythonSubWindows/
所以,使用您当前的代码:
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()
如果使用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")
而且,在最新版本中,可以将许多属性设置为参数,并且有添加小部件的新功能:
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")