wxpython 可视化GUI库学习之路----1

wxpyhton整体是app()->frame.show()->mainloop()

app = wx.App()
frame = wx.Frame(None, ID_ANY, "title")
frame.Show()
app.MainLoop()

这是最基本的一个框框,也就是wxpython的hello world
如果需要更加复杂的功能,那么就需要对frame类进行改写

如果要让frame添加一个打字版,那就要在重写frame,在init中添加TextCtrl

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(500,500))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.Show()

比如说添加一个menu,那么就需要在frame中重写(overwrite)”init“(这个init前后是有两个下划线的,不知道为什么显示不出来)

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(500,500))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)

        filemenu  = wx.Menu()

        filemenu.Append(wx.ID_ABOUT, "About", "information")
        filemenu.AppendSeparator()
        filemenu.Append(wx.ID_EXIT, "EXIT", "go away")
        filemenu.Append(wx.ID_ABOUT, "else", "others")

        menuBar = wx.MenuBar()
        menuBar.Append(filemenu, "file")
        self.SetMenuBar(menuBar)
        self.Show()

猜你喜欢

转载自blog.csdn.net/Big_Head_/article/details/81023262