我创建了一个GUI,向用户询问用户/密码。创建GUI的类调用另一个创建web浏览器的类,并尝试使用同一类的方法登录网站。如果登录成功,GUI对象的变量将变为“True”
我的主文件是下一个:
from AskUserPassword import AskGUI
from MainInterfaceGUI import MainGUI
Ask = AskGUI()
Ask = Ask.show()
MainInterface = MainGUI()
if Ask.LoginSuccesful == True:
Ask.close()
MainInterface.show()
如果登录成功,我想隐藏用户/密码GUI并显示主GUI。上面的代码显然不起作用
如何使Python等待这种类型的条件得到满足
与其不断地检查要满足的条件,为什么不在登录时提供您想要做的作为对
AskGUI
对象的回调,然后让AskGUI
对象在尝试登录时调用回调呢?比如:然后,在
AskGUI
中,当单击登录按钮并检查凭据时,您将执行以下操作:Re
我推荐这种方式,因为所有处理登录时发生的事情的代码都包含在需要进行登录的类中。处理要显示的UI元素(
on_login()
)的代码包含在处理该元素的类中。 您不需要在后台不断检查Ask.LoginSuccessful
是否已更改。 当您使用一个像样的IDE时,很容易跟踪每个函数的定义位置相关问题 更多 >
编程相关推荐