WxPython窗口不会弹出

时间:2014-03-25 07:33:43

标签: python wxpython

我写了以下代码片段来显示一个简单的窗口。

然而它既没有显示窗口也没有报告任何错误:

import wx    
class myFrame (wx.App) :
        def __init__(self):
            x = wx.Frame.__init__(self, "", size=(200,200), title="Thanks", style= wx.SYSTEM_MENU |  wx.CLOSE_BOX | wx.CLOSE)
            x.Show(True)

    frm = wx.App(False)
    things = myFrame
    frm.MainLoop()

1 个答案:

答案 0 :(得分:2)

您的代码中存在一些问题 您可能希望从以下代码开始:

import wx

class myFrame (wx.Frame):         #inherits from a Frame not from an Application
      def __init__(self, parent):
          wx.Frame.__init__(self, parent, -1, size=(200,200), title="Thanks")
          # Note the order of the three positional arguments above
          # Second one is the parent frame (None here) and the third the window ID


frm = wx.App(False)
things = myFrame(None)           # you must call the class to create an instance
things.Show()                    # this is the correct position to show it
frm.MainLoop()

如果您运行代码,则会得到一个空框架。从这里你可以尝试不同的风格。