平台:Windows、OS X
Python 版本:活动状态 Python 2.7
wxPython 版本:2.9 版
这是我使用 wxMessageBox 的示例代码:
import wx,os
class Frame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(100, 100),style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
host=os.system('hostname')
if host!='superman':
self.dialogBox=wx.MessageBox('The host name should be superman. Closing this dialog box in 2s...','Info')
self.Destroy()
else:
self.Center()
self.Show()
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = Frame(None, -1, 'Sample')
app.MainLoop()
根据上面的代码,如果主机名不是 'superman' ,则会显示一个消息框并提示用户按'OK'。如果用户按下消息框上的“确定”按钮,则控件将移动到代码中的下一行(即第 10 行),其中框架被销毁。我希望能够自动关闭对话框并转到代码中的下一行,即self.Destroy()
如果用户在接下来的 2 秒内没有按下“确定”按钮。关于如何在 wxpython 中做到这一点的任何想法?