wxpython教程 中谷

点击(此处)折叠或打开

  1. #导入库

  2. import wx

  3. #实例化一个app

  4. app=wx.App()

  5. #创建一个Frame

  6. win = wx.Frame(None,title="HelloWorld!!",size=(450,300))

  7. """

  8. OpenBtn = wx.Button(win,label="Open",size=(80,25),pos=(315,0))

  9. SaveBtn = wx.Button(win,label="Save",size=(80,25),pos=(230,0))

  10. """

  11. #打开布局画板

  12. Bkg=wx.Panel(win)


  13. #创建一个水平布局箱子

  14. Hbox=wx.BoxSizer(wx.HORIZONTAL)


  15. OpenBtn = wx.Button(Bkg,label="Open")

  16. SaveBtn = wx.Button(Bkg,label="Save")

  17. NameTxtCtl = wx.TextCtrl(Bkg)

  18. Hbox.Add(NameTxtCtl,proportion=1,flag=wx.EXPAND)

  19. Hbox.Add(OpenBtn,proportion=0,flag=wx.LEFT,border=5)

  20. Hbox.Add(SaveBtn,proportion=0,flag=wx.LEFT,border=5)


  21. ContentsTxtCtl=wx.TextCtrl(Bkg)


  22. #创建一个垂直布局箱子

  23. Vbox=wx.BoxSizer(wx.VERTICAL )

  24. Vbox.Add(Hbox,proportion=0,flag=wx.EXPAND|wx.ALL,border=5)

  25. Vbox.Add(ContentsTxtCtl,proportion=1,flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border=5)

  26. Bkg.SetSizer(Vbox)

  27. #显示

  28. win.Show()

  29. #主循环

  30. app.MainLoop()



运行结果:



转自:http://blog.chinaunix.net/uid-29630160-id-4705703.html