Frage

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()
War es hilfreich?

Lösung

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()

Andere Tipps

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()
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top