我正在将登录窗口连接到主窗口,但是我需要将登录用户名传递给下一个窗口,注意它们位于不同的类中。
我的下面的代码:
29032019:{
morning:[{
person : 1,
name:'abc',
cancelled:false
},
{
person : 2,
name:'abc',
cancelled:false
}
],
afternoon:[{
person : 3,
name:'abc',
cancelled:false
},
{
person : 4,
name:'abc',
cancelled:false
}
]
}
30032019:{
morning:[{
person : 5,
name:'abc',
cancelled:false
},
{
person : 2,
name:'abc',
cancelled:false
}
],
afternoon:[{
person : 6,
name:'abc',
cancelled:false
},
{
person : 7,
name:'abc',
cancelled:false
}
]
}
答案 0 :(得分:0)
在主窗口中,创建一个setter函数,该函数允许您设置名称String。从登录窗口适当地调用/调用(假定主窗口创建登录窗口并为子级提供对自身的引用)。如果要将登录结果传递到新窗口,只要主窗口创建相关的后续/子窗口,这也将起作用。
以下代码(我尚未验证其功能,可能需要对其进行更改)应该使您入门:
# in Main class:
def setName(n):
if n is not None and len(n) > 0: # Check might not be required if you're OK with empty names
self.name = n
# in function that creates login Window, create the login window with a reference
# window creation might already take a "parent" param, in which case you're all set.
createLoginWindow(requiredParams, main=self)
# in LoginWindow init/constructor:
self.mainWindow = main
# When name changes:
self.mainWindow.setName(name)