문제

i'm a newby and am trying to learn wxpython. i got this code off a video tutorial on youtube. it's supposed to show a dialog box with an 'ok' button. it works in the demo in the video, but the dialog box just doesn't appear when i do it. i added the print statements to debug the code. the program seems to be going through all the steps but the dialog box just doesn't appear.

i also get this message in the terminal console: Python[3700:d07] Can't open input server /Library/InputManagers/Inquisitor

thanks in advance,

here's the code:

import wx

class bucky(wx.Frame):

    def __init__(self, parent, id):
        print 'initialising frame'
        wx.Frame.__init__(self,parent, id, 'frame aka window', size=(300,200))
        panel = wx.Panel(self)


        print 'about to create box'

        box = wx.MessageDialog(None,'go on', 'title', wx.OK)
        answer=box.ShowModal()
        box.Destroy()


if __name__=='__main__':
    print 'program begins'
    app=wx.App()
    print 'app created'
    frame = bucky(parent=None, id=-1)
    print 'frame instantiated'
    frame.Show()
    app.MainLoop()
도움이 되었습니까?

해결책

The same problem, still can't figure out why the dialog is cancelled when initiated, but we can initiate it twice to solve that.

    box = wx.MessageDialog(None,'go on', 'title', wx.OK)
    box.ShowModal()
    box.ShowModal()
    box.Destroy()

다른 팁

Try this code. It worked fine on windows 8 with wxPython v3.0

import wx

class bucky(wx.Frame):
    def __init__(self, parent, id):
        print 'initialising frame'
        wx.Frame.__init__(self,parent, id, 'frame aka window', size=(300,200))
        panel = wx.Panel(self)
        print 'about to create box'
        box = wx.MessageDialog(None,'go on', 'title', wx.OK)
        box.ShowModal()
        box.Destroy()

if __name__=='__main__': 
    print 'program begins' 
    app=wx.App() 
    print 'app created' 
    frame = bucky(parent=None, id=-1) 
    print 'frame instantiated' 
    frame.Show()
    app.MainLoop()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top