繁体   English   中英

使用 appJar GUI 模块化 Python 程序

[英]Modualrize Python program with appJar GUI

如何模块化 appJar 应用程序? 当我尝试使用示例代码并将press() function 移动到自己的文件中时,此函数不知道 app 变量。 我想最好看看下面的图片 - 如果没有,我会更新问题!

例子

至于我,将press()放在单独的文件中并不是一个好主意。 我宁愿将press()保留在当前文件中,它可以使用其他文件中的 function - 但该文件应将所有值作为 arguments

模块/方法.py

def display(app):
    print("User:", app.entry("Username"), "Pass:", app.entry("Password"))

主文件

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])

或者其他事件 function 应该只从小部件中获取值

模块/方法.py

def display(username, password):
    print("User:", username, "Pass:", password)

主文件

def press():
    methods.display(app.entry("Username"), app.entry("Password"))

如果您真的想在其他文件中使用press() ,那么它应该将app作为参数

模块/方法.py

def press(app):
    print("User:", app.entry("Username"), "Pass:", app.entry("Password"))

但是你必须使用lambda:methods.press(app)分配给按钮 function 和参数。

主文件

app.buttons(["Submit", "Cancel"], [lambda:methods.press(app), app.stop])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM