在 Python 中从自定义对话框返回值
Returning value from custom Dialog in Python
我有一个名为 queryURI 的函数,它可以打开一个自定义对话框,该对话框包含用于获取用户输入的代码。
def queryURI(self,e):
global outDir
dlg = queryURIDlg()
dlg.ShowModal()
dlg.Destroy()
self.ProgressBox.AppendText('Querying ' + [return value to go in here])
单击 'OK' 按钮时,它会启动一个名为 retValue 的函数,它从文本框中获取文本值,并根据选中的单选按钮分配值。然后我想 return 这些字符串值。我试过 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()
如何正确地 return 来自自定义对话框的值?
我建议为对话框使用上下文管理器"with",当不再使用对话框时它会销毁它。您需要在 ShowModal returns 之后从对话框使用中获取您感兴趣的值。
def queryURI(self,e):
global outDir
valueYouWant = ""
with queryURIDlg() as dlg:
dlg.ShowModal()
valueYouWant = dlg.getYourValue()
self.ProgressBox.AppendText('Querying ' + valueYouWant)
我有一个名为 queryURI 的函数,它可以打开一个自定义对话框,该对话框包含用于获取用户输入的代码。
def queryURI(self,e):
global outDir
dlg = queryURIDlg()
dlg.ShowModal()
dlg.Destroy()
self.ProgressBox.AppendText('Querying ' + [return value to go in here])
单击 'OK' 按钮时,它会启动一个名为 retValue 的函数,它从文本框中获取文本值,并根据选中的单选按钮分配值。然后我想 return 这些字符串值。我试过 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()
如何正确地 return 来自自定义对话框的值?
我建议为对话框使用上下文管理器"with",当不再使用对话框时它会销毁它。您需要在 ShowModal returns 之后从对话框使用中获取您感兴趣的值。
def queryURI(self,e):
global outDir
valueYouWant = ""
with queryURIDlg() as dlg:
dlg.ShowModal()
valueYouWant = dlg.getYourValue()
self.ProgressBox.AppendText('Querying ' + valueYouWant)