我有一个名为queryURI的函数,它打开一个自定义Dialog,这个Dialog包含从用户那里获取输入的代码。
def queryURI(self,e):
global outDir
dlg = queryURIDlg()
dlg.ShowModal()
dlg.Destroy()
self.ProgressBox.AppendText('Querying ' + [return value to go in here])
当' OK'单击按钮,它启动一个名为retValue的函数,它从文本框中获取文本值,并根据选中的单选按钮分配值。然后我想返回这些字符串值。我尝试过EndModal(),但不要以为我正确使用它。
def retValue(self,e):
uriTxt = self.uriTxt.GetValue()
if self.inj1.GetValue() == True:
uriInj = ' --vertical'
elif self.inj2.GetValue() == True:
uriInj = self.inj2Txt.GetValue()
uriTxt = uriTxt + uriInj
uri = EndModal(uriTxt)
self.Destroy()
如何从自定义对话框中正确返回值?
答案 0 :(得分:0)
我建议在对话框中使用上下文管理器“with”,当不再使用对话框时,它会销毁它。在ShowModal返回后,您需要从对话框中获取您感兴趣的值。
def queryURI(self,e):
global outDir
valueYouWant = ""
with queryURIDlg() as dlg:
dlg.ShowModal()
valueYouWant = dlg.getYourValue()
self.ProgressBox.AppendText('Querying ' + valueYouWant)