0

我正在使用 Python 和 wxPython 在我的用户和 USB 设备之间进行交互。USB 设备在处理命令方面有些慢。因此,在发送命令后,我会显示一个对话框,通知用户该命令并给设备足够的时间来处理该命令。编码:

def ActionOnButtonClick( self, event ):
    # Send command to USB device;
    device.Send("command")

    # Notify user + allowing device to process command;
    dlg = wx.MessageDialog(parent=None, message="Info", caption="Info", style=wx.OK)
    dlg.ShowModal()
    dlg.Destroy()

    # Start timer;
    self.RunTimer.Start(500)

当我像这样运行代码时,“RunTimer”只会运行一次。经过一些测试,我注意到当我删除消息对话框时,RunTimer 将连续运行而没有任何问题。

我无法弄清楚我做错了什么。有什么想法/想法吗?

预先感谢您的回答!

此致,

彼得

4

1 回答 1

0

@soep 你能运行这个测试代码吗?如果有疑问,请从基础开始。

import wx

class Frame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, title="Timer Dialog Test")
        self.button_1 = wx.Button(self, 1, label="Start Timer")
        self.button_1.Bind(wx.EVT_BUTTON, self.OnButton, id=1)
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.button_1, 0, wx.ALL, 5)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        self.timer = wx.Timer(self)
        self.breaktimer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

    def OnTimer(self, evt):
        print "timer"

    def OnButton(self,evt):
        dlg = wx.MessageDialog(parent=None, message="Starting Timer", caption="Timer Info", style=wx.OK)
        dlg.ShowModal()
        dlg.Destroy()
        self.timer.Start(1000)

if __name__ == "__main__":
    app = wx.App()
    frame = Frame(None)
    frame.Show()
    app.MainLoop()
于 2015-08-27T14:48:55.023 回答