[英]Modualrize Python program with appJar GUI
How do you modularize an appJar app?如何模块化 appJar 应用程序? When I try to use the example code and move the
press()
function into an own file, this functions doesn't know the app variable.当我尝试使用示例代码并将
press()
function 移动到自己的文件中时,此函数不知道 app 变量。 I guess it's best if you look at the Image below - if not I'll update the question!我想最好看看下面的图片 - 如果没有,我会更新问题!
As for me it is not good idea to put press()
in separated file.至于我,将
press()
放在单独的文件中并不是一个好主意。 I would rather keep press()
in current file and it could use function from other file - but this file should get all values as arguments我宁愿将
press()
保留在当前文件中,它可以使用其他文件中的 function - 但该文件应将所有值作为 arguments
modules/methods.py模块/方法.py
def display(app):
print("User:", app.entry("Username"), "Pass:", app.entry("Password"))
main.py主文件
from appJar import gui
from modules import methods
def press():
methods.display(app)
with gui("Login Window", "400x200", bg='orange', font={'size':18}) as app:
app.label("Welcome to appJar", bg='blue', fg='orange')
app.entry("Username", label=True, focus=True)
app.entry("Password", label=True, secret=True)
app.buttons(["Submit", "Cancel"], [press, app.stop])
Or event other function should get only values from widgets或者其他事件 function 应该只从小部件中获取值
modules/methods.py模块/方法.py
def display(username, password):
print("User:", username, "Pass:", password)
main.py主文件
def press():
methods.display(app.entry("Username"), app.entry("Password"))
If you really want press()
in other file then it should get app
as argument如果您真的想在其他文件中使用
press()
,那么它应该将app
作为参数
modules/methods.py模块/方法.py
def press(app):
print("User:", app.entry("Username"), "Pass:", app.entry("Password"))
but then you have to use lambda:methods.press(app)
to assign to button function with argument.但是你必须使用
lambda:methods.press(app)
分配给按钮 function 和参数。
main.py主文件
app.buttons(["Submit", "Cancel"], [lambda:methods.press(app), app.stop])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.