当前位置:Linux教程 - Linux综合 - wxPython的demo代码分析之一(wxScrolledPanel)

wxPython的demo代码分析之一(wxScrolledPanel)

  [myPHP] #!/usr/bin/env python # -*- coding:gb2312 -*- #导入模块,注意wxScrolledPanel是 #wXPython.lib.scrolledpanel中的了类 from wxPython.wx import * from wxPython.lib.scrolledpanel import wxScrolledPanel #定义一个字符串 text = "one two bUCkle my shoe three four shut the door five six pick up sticks seven eight lay them straight nine ten big fat hen" #定义一个新类 class TestPanel(wxScrolledPanel): def __init__(self, parent): #调用父类的构造函数 wxScrolledPanel.__init__(self, parent, -1) #定一个新的布局框 vbox = wxBoxSizer(wxVERTICAL) #定义一个静态标签 desc = wxStaticText(self, -1, u"wxScrolledPanel标签") desc.SetForegroundColour("Blue") #向布局管理器中增加控件 vbox.Add(desc, 0, wxALIGN_LEFTwxALL, 5) vbox.Add(wxStaticLine(self, -1, size=(1024, -1)), \ 0, wxALL, 5) vbox.AddSpacer(20, 20) #建立一个表格式的布局管理器 Words = text.split() #拆分一个字符串 #增加一个面板,然后在面板上加入布局管理器和控件 panel1 = wxScrolledPanel(self, -1, size=(120, 300), \ #增加一个面板,然后在面板上加入布局管理器和控件 panel1 = wxScrolledPanel(self, -1, size=(120, 300), \
[1] [2] [3] 下一页 

style = wxTAB_TRAVERSALwxSUNKEN_BORDER) fgs1 = wxFlexGridSizer(cols=2, vgap=4, hgap=4) for word in words: label = wxStaticText(panel1, -1, word + ":") tc = wxTextCtrl(panel1, -1, word, size=(50, -1)) fgs1.Add(label, flag=wxALIGN_RIGHTwxALIGN_CENTER_VERTICAL) fgs1.Add(tc, flag=wxEXPANDwxRIGHT, border=25) #设置面板1的布局管理为fgs1,并设置为自动布局 panel1.SetSizer(fgs1) panel1.SetAutoLayout(1) panel1.SetupScrolling(scroll_x=False) #第二个面板 panel2 = wxScrolledPanel(self, -1, size=(350, 40), \ style=wxTAB_TRAVERSALwxSUNKEN_BORDER) panel3 = wxScrolledPanel(self, -1, size=(200, 100), \ style=wxTAB_TRAVERSALwxSUNKEN_BORDER) fgs2 = wxFlexGridSizer(cols=25, vgap=4, hgap=4) fgs3 = wxFlexGridSizer(cols=5, vgap=4, hgap=4) for i in range(len(words)): word = words[i] if ( i % 5 != 4 ) : label2 = wxStaticText(panel2, -1, word) fgs2.Add(label2, flag=wxALIGN_LEFTwxALIGN_CENTER_VERTICAL) label3 = wxStaticText(panel3, -1, word) fgs3.Add(label3, flag=wxALIGN_LEFTwxALIGN_CENTER_VERTICAL) else : tc2 = wxTextCtrl(panel2, -1, word, size=(50, -1)) fgs2.Add(tc2, flag=wxLEFT, border=5) tc3 = wxTextCtrl(panel3, -1, word) fgs3.Add(tc3, flag=wxLEFT, border=5) tc3 = wxTextCtrl(panel3, -1, word) fgs3.Add(tc3, flag=wxLEFT, border=5) panel2.SetSizer(fgs2) panel2.SetAutoLayout(1) panel2.SetupScrolling(scroll_y=False)
上一页 [1] [2] [3] 下一页 

panel3.SetSizer(fgs3) panel3.SetAutoLayout(1) panel3.SetupScrolling() hbox = wxBoxSizer(wxHORIZONTAL) hbox.AddSpacer(20, 20) hbox.Add(panel1, 0) hbox.AddSpacer(40, 10) vbox2 = wxBoxSizer(wxVERTICAL) vbox2.Add(panel2, 0) vbox2.AddSpacer(20, 50) vbox2.Add(panel3, 0) vbox2.AddSpacer(20, 10) hbox.Add(vbox2) vbox.AddSizer(hbox, 0) self.SetSizer(vbox) self.SetAutoLayout(1) self.SetupScrolling() #定义一个新的frame class MyFrame(wxFrame): def __init__(self): wxFrame.__init__(self, None, -1, u"我的程序") w = TestPanel(self) #定义一个新的应用程序类 #定义一个新的应用程序类 class MyApp(wxApp): def OnInit(self): f = MyFrame() f.Show(true) self.SetTopWindow(f) return true if (__name__ == "__main__"): a = MyApp(0) a.MainLoop() [/myphp]

(出处:http://www.sheup.com)


上一页 [1] [2] [3] 

#定义一个新的frame class MyFrame(wxFrame): def __init__(self): wxFrame.__init__(self, None, -1, u"我的程序") w = TestPanel(self) #定义一个新的应用程序类 #定义一个新的应用程序类 class MyApp(wxApp): def OnInit(self): f = MyFrame() f.Show(true) self.SetTopWindow(f) return true if (__name__ == "__main__"): a = MyApp(0) a.MainLoop() [/myphp]

(出处:http://www.sheup.com)


上一页 [1] [2] [3] [4] 

f = MyFrame() f.Show(true) self.SetTopWindow(f) return true if (__name__ == "__main__"): a = MyApp(0) a.MainLoop() [/myphp]

(出处:http://www.sheup.com/)


上一页 [1] [2] [3] [4] [5]