我用..。
waitingdlg = wx.MessageDialog(self, 'Waiting for soundcard signal...', 'Test', wx.CANCEL)
waitingdlg.ShowModal()
while inputvolume < 10: # inputvolume is a global variable
# modified by another thread linked to soundcard input
wx.MilliSleep(10)
waitingdlg.Destroy()..。为了等待外部信号(例如:声卡的输入电平更高到某个分贝电平)。
我希望wx.MessageDialog在触发器发生时自动关闭(当inputvolume变成>= 10时)。
但是由于waitingdlg.ShowModal(),while从来没有发生过!另一方面,如果没有ShowModal,则不会显示对话框。
如何使这个wx.MessageDialog等待外部触发器关闭?
发布于 2014-02-11 17:52:01
您可以创建另一个线程来检查volum。请使用wx.Dialog代替,因为wx.MessageDialog不是真正的wx.Dialog,它不会响应wx.Dialog()。
import wx
import threading
def timer_start(dlg):
t = threading.Timer(0,test_func,(dlg,))
t.start()
def test_func(dlg):
global inputvolume
print "inputvolume: ", inputvolume
if inputvolume < 100:
wx.MilliSleep(10)
timer_start(dlg)
inputvolume += 1
else:
#dlg.EndModal(wx.CANCEL)
dlg.Destroy()
if __name__ == "__main__":
inputvolume = 0
app = wx.App(False)
fame = wx.Frame(None)
fame.Show()
waitingdlg = wx.Dialog(fame,title = 'Test')
timer_start(waitingdlg)
waitingdlg.ShowModal()
app.MainLoop()https://stackoverflow.com/questions/21707438
复制相似问题