[Python]wxpython中Frame所用到的主要控件以及方法

[Python]wxpython中Frame所用到的主要控件以及方法

 

接下来几天的内容将分为三部分讲述frame.py、guimanager.py和main.py.

*基于wxpython.

第一部分 | 图形界面绘制与功能设计:frame.py

将要用到的库

importwximportwx.lib.buttonsaswxbutton#wxpython中一个专门的按钮库import_threadasthread#多线程支持,提高成绩列表刷新速度fromoperatorimportitemgetter#用于列表排序时指定keyfromanalysisimportparser_datafromorignal_dataimportget_code_in_file

*analysis.py和orignal_data.py是自有文件.

wxpython窗体框架的主要结构

classMyFrame(wx.Frame):def__init__(self, parent=None, id=-1, title='窗口标题', size=wx.DefaultSize,            style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX|wx.RESIZE_BORDER)):wx.Frame.__init__(self, parent, id, title=title, size=size, style=style)        self.InitUI()#self.Center()  #窗体居中defInitUI(self):pass

上面是窗体的基本框架,

可以试着运行一下下面的代码,感受一下~

importwxclassMyFrame(wx.Frame):def__init__(self, parent=None, id=-1, title='窗口标题', size=wx.DefaultSize,            style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX|wx.RESIZE_BORDER)):wx.Frame.__init__(self, parent, id, title=title, size=size, style=style)        self.InitUI()#self.Center()  #窗体居中defInitUI(self):passclassApp(wx.App):defOnInit(self):myframe =MyFrame()        myframe.Show()#self.SetTopWindow(myframe)  #窗体置顶returnTruedefmain():myapp = App()    myapp.MainLoop()if__name__ =='__main__':    main()

运行结果如图所示:

我们有必要了解一下wxpython库中的几个基本组件:

wx.TextCtrl - 文本框控件

主要参数:wx.TextCtrl(parent,id=ID_ANY,value="",pos=DefaultPosition,size=DefaultSize,style=0,validator=DefaultValidator,name=TextCtrlNameStr)

wx.StaticText - 静态文本

主要参数:wx.StaticText(parent,id=ID_ANY,label="",pos=DefaultPosition,size=DefaultSize,style=0,name=StaticTexNameStr)

wx.Button or wxbutton.GenButton - 按钮控钮https://docs.wxpython.org/wx.Button.html#wx.Button

主要参数:wx.Button(parent,id=ID_ANY,label="",pos=DefaultPosition,size=DefaultSize,style=0,validator=DefaultVaidator,name=ButtonNameStr)

wx.Choice - 下拉可选列表(菜单)控件https://docs.wxpython.org/wx.Choice.html#wx.Choice

主要参数:wx.Choice(parent,id=ID_ANY,pos=DefaultPosition,size=DefaultSize,choices[],style=0,validator=DefaultValidator, name=ChoiceNameStr)

wx.ListCtrl - 列表控件 https://docs.wxpython.org/wx.ListCtrl.html#wx.ListCtrl

主要参数:wx.ListCtrl(parent,id=ID_ANY,pos=DefaultPosition,size=DefaultSize,style=LC_ICON,validator=DefaultValidator, name=ListCtrlNameStr)

该类支持以下样式(主要用到wx.LC_REPORT):

wx.LC_LIST:多列列表视图,带有可选的小图标。列是自动计算的,即您不设置列,如 LC_REPORT。换句话说,与 wx.ListBox不同,列表包装 。

wx.LC_REPORT:单列或多列报表视图,带有可选标头。

wx.LC_VIRTUAL:应用程序按需提供项目文本。可能只能用于 LC_REPORT。

wx.LC_ICON:大图标视图,带有可选标签。

wx.LC_SMALL_ICON:小图标视图,带有可选标签。

wx.LC_ALIGN_TOP:图标对齐顶部。Win32默认,仅限Win32。

wx.LC_ALIGN_LEFT:图标左对齐。

wx.LC_AUTOARRANGE:图标安排自己。仅限Win32。

wx.LC_EDIT_LABELS:标签可编辑:编辑开始时将通知应用程序。

wx.LC_NO_HEADER:报告模式下没有标题。

wx.LC_SINGLE_SEL:单选(默认为多个)。

wx.LC_SORT_ASCENDING:按升序排序。(你仍然必须提供比较回调wx.ListCtrl.SortItems。)

wx.LC_SORT_DESCENDING:按降序排序。(你仍然必须提供比较回调wx.ListCtrl.SortItems。)

wx.LC_HRULES:在报告模式下在行之间绘制浅水平规则。报告模式下使用增加美观度。

wx.LC_VRULES:在报告模式下在列之间绘制明亮的垂直规则。报告模式下使用增加美观度。

wx.BoxSizer - 对控件进行排版https://docs.wxpython.org/wx.BoxSizer.html#wx.BoxSizer

主要参数:wx.BoxSizer(orient=HORIZONTAL) #可能的结构

wx.Icon - 程序图标控件

主要参数:wx.Icon(name, type=BITMAP_TYPE_ANY, desiredWidth=-1, desiredHeight=-1)

以及几个基本方法(基于wx.Frame类可使用的方法):

self.Center() - 窗体居中

self.SetIcon(icon) - 设置程序图标

self.listctrl.InsertColumn (col, heading, format=LIST_FORMAT_LEFT, width=LIST_AUTOSIZE) - 插入头部标签到列表

-功能解释:

For report view mode (only), inserts a column.

Insert a new column in the list control in report view mode at the given position specifying its most common attributes.

Notice that to set the image for the column you need to use Insert(long, ListItem&) overload and specify LIST_MASK_IMAGE in the item mask.

参数解释:

col (long) – The index where the column should be inserted. Valid indices are from 0 up to GetColumnCount inclusive and the latter can be used to append the new column after the last existing one.

heading (string) – The string specifying the column heading.

**format (int)(( – The flags specifying the control heading text alignment.

width (int) – If positive, the width of the column in pixels. Otherwise it can be LIST_AUTOSIZE to choose the default size for the column or LIST_AUTOSIZE_USEHEADER to fit the column width to heading or to extend to fill all the remaining space for the last column. Notice that in case of LIST_AUTOSIZE fixed width is used as there are no items in this column to use for determining its best size yet. If you want to fit the column to its contents, use SetColumnWidth after adding the items with values in this column.

self.listctrl.SetItem(index(行, self.listctrl.InsertItem()[object]),column(列, int),label(要插入的数据, string),imageId = -1) - 设置特定列项的字符串

self.object.SetForegroundColour('#888888') - 设置对象的背景文本颜色(RGB格式的颜色)

self.choice_obj.SetSelection(0) - 设置下拉列表的先选项

self.choice_obj.SetString(0, 'title') - 设置下拉列表某选项的标签

boxsizer.Add() - 添加控件到boxsizer

主要参数: Add(window(控件), proportion(比例)=0, flag=0, border(间隔)=0, userData=None)

*一种主流方法,可查阅:https://www.yiibai.com/wxpython/wx_boxsizer.html。

功能解释:Appends a child to the sizer.

wx.Sizer itself is an abstract class, but the parameters are equivalent in the derived classes that you will instantiate to use it so they are described here.

参数解释:

window (wx.Window) – The window to be added to the sizer. Its initial size (either set explicitly by the user or calculated internally when using DefaultSize) is interpreted as the minimal and in many cases also the initial size.

proportion (int) – Although the meaning of this parameter is undefined in wx.Sizer, it is used in wx.BoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wx.BoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative to the value of other children of the same wx.BoxSizer. For example, you might have a horizontal wx.BoxSizer with three children, two of which are supposed to change their size with the sizer. Then the two stretchable windows would get a value of 1 each to make them grow and shrink equally with the sizer’s horizontal dimension.

flag (int) – OR-combination of flags affecting sizer’s behaviour. See Sizer flags list for details.

border (int) – Determines the border width, if the flag parameter is set to include any border flag.

userData (PyUserData) – Allows an extra object to be attached to the sizer item, for use in derived classes when sizing information is more complex than the proportion and flag will allow for.

关于flag的参数可选项

对齐标志

wx.ALIGN_TOP

wx.ALIGN_BOTTOM

wx.ALIGN_LEFT

wx.ALIGN_RIGHT

wx.ALIGN_CENTER_VERTICAL

wx.ALIGN_CENTER_HORIZONTAL

边界标志

wx.TOP

wx.BOTTOM

wx.LEFT

wx.RIGHT

wx.ALL

行为标志和说明

wx.EXPAND

项目将扩大,以填补提供给它的空间(wx.GROW是一样的)

wx.SHAPED

与EXPAND相似,但保持了项目的高宽比

wx.FIXED_MINSIZE

不允许该项目变得比其最初的最小尺寸更小

wx.RESERVE_SPACE_EVEN_IF_ HIDDEN

不允许测量器(sizer)回收项目空间,当它被隐藏时

self.panel.SetSizerAndFit(boxsizer) - 应用boxsizer中的设置

self.listctrl.ClearAll() - 清空列表内容

具体各方法的参数详情请查阅wxpython库官方文档:https://docs.wxpython.org/

下面介绍教务网查成绩小工具的主要功能及其代码实现:

点击获取\刷新验证码的按钮,刷新显示验证码。

defimage_show(self):'验证码显示'image = wx.Image('code.jpg', wx.BITMAP_TYPE_JPEG)        temp = image.ConvertToBitmap()        self.bmp = wx.StaticBitmap(parent=self.panel, bitmap=temp, pos=(420,40))defFresh_Code(self, event):'刷新验证码'self.cookies = get_code_in_file()        self.image_show()

点击查询成绩按钮,按之前文本框输入的登录信息以及下拉菜单的所选项模拟登陆教务网,爬取数据然后显示成绩(分级显示)。

defOnRefresh(self,event):'多线程刷新列表'try:            self.get_data()except:            print("用户未登录,成绩无法获取!")ifself.data:            thread.start_new_thread(self.SetData,(0, ))else:            self.OnClick()defget_data(self):'获取成绩数据'index = self.listbox.GetSelection()        temp = [self.text.GetValue(), self.text1.GetValue(), self.list1[index]]        verifycode_ = self.code_text.GetValue()        self.data = parser_data(verifycode_, self.cookies, temp[0], temp[1], temp[-1])ifself.data == []:            self.OnClick()defSetData(self, pos):'将数据插入到列表,不同成绩段显示不同颜色'self.list.ClearAll()        self.CreateHeader()foreachinself.data:            pos = self.list.InsertItem(pos+1,each[0])foriinrange(1,11):                self.list.SetItem(pos,i,each[i])            grade = each[4]try:ifint(grade) <60:                    self.list.SetItemBackgroundColour(pos, (255,0,0))#挂科显示为红色elifint(grade) <=61:                    self.list.SetItemBackgroundColour(pos, (255,99,71))#60到61为浅红elifint(grade) <=74:                    self.list.SetItemBackgroundColour(pos, (238,221,130))#62到74为黄elifint(grade) <=84:                    self.list.SetItemBackgroundColour(pos, (152,251,152))#75到84为浅绿elifint(grade) <=100:                    self.list.SetItemBackgroundColour(pos, (124,252,0))#85到100为绿except:passifgrade =='不及格':                self.list.SetItemBackgroundColour(pos, (255,0,0))#挂科显示为红色elifgrade =='及格'andeach[3] !='军事技能训练':                self.list.SetItemBackgroundColour(pos, (255,99,71))#及格为浅红elifgrade =='中':                self.list.SetItemBackgroundColour(pos, (238,221,130))#中为黄elifgrade =='良'oreach[3] =='军事技能训练':                self.list.SetItemBackgroundColour(pos, (152,251,152))#良为浅绿,军训特殊,大部分为及格,显示为浅绿elifgrade =='优':                self.list.SetItemBackgroundColour(pos, (124,252,0))#优为绿

点击列表中的任一头部标签,按此标签对列表进行排序。

defsort_by_column(self, listevent):'按指定标签正序排序列表'num = listevent.GetColumn()#with open('data.json', 'w') as f:#    f.write(json.dumps(self.data, ensure_ascii=False, indent=4, sort_keys=False))self.data = sorted(self.data, key=itemgetter(num))        self.SetData(pos=0)defsort_by_column_reversed(self, listevent):'按指定标签逆序排序列表'num = listevent.GetColumn()        self.data = sorted(self.data, key=itemgetter(num), reverse=True)        self.SetData(pos=0)

出错时跳出Tips窗体,点击帮助按钮跳出Hlep窗体。

defOnClick(self):'切换到窗体TipsFrame'self.UpdateUI(1)defOnClick_Help(self, event):'切换到窗体HelpFrame'self.UpdateUI(2)

请看frame.py的全部Codes.

importwximportwx.lib.buttonsaswxbuttonimport_threadasthreadfromoperatorimportitemgetterfromanalysisimportparser_datafromorignal_dataimportget_code_in_fileclassMainFrame(wx.Frame):def__init__(            self, parent=None, id=-1, title='HNUST教务网成绩查询小工具  by:王S  微信公众号:Wang的胜宴  来关注 一起学习吧 ~',size=wx.DefaultSize,            style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX|wx.RESIZE_BORDER), UpdateUI=None    ):wx.Frame.__init__(self, parent, id, title=title, size=size, style=style)                self.data = []#数据初始化self.UpdateUI = UpdateUI        self.InitUI()#绘制UI界面self.Center()defInitUI(self):#绘制面板self.panel = wx.Panel(self)#软件图标self.Software_Icon()#文本控件集self.Textctrl()#成绩列表框self.Grades_List()#按钮集self.Buttons()#控件容器self.Boxsizer()#程序事件处理self.Event_deal()defSoftware_Icon(self):'设置图标'icon = wx.Icon('hnust(black).ico', wx.BITMAP_TYPE_ICO)        self.SetIcon(icon)defChoice_Listbox(self):'选择框控件初始化'self.list1 = ['','2018-2019-1','2017-2018-2','2017-2018-1','2016-2017-2','2016-2017-1','2016-2015-2','2016-2015-1','2015-2014-2','2015-2014-1']#可选项self.listbox = wx.Choice(self.panel,-1, choices=self.list1)        self.listbox.SetSelection(0)#初选项self.listbox.SetString(0,'全部成绩')#给指定项设置标签defComment(self):#注释静态文本#self.s_text = wx.StaticText(self.panel, label='*输入学号后按回车也\n 可以获取验证码哦~')#self.s_text1 = wx.StaticText(self.panel, label='*教务网密码输入框')#self.s_text2 = wx.StaticText(self.panel, label='*选择空白为查询全部成绩', pos=(250,38))#self.s_text3 = wx.StaticText(self.panel, label='*刷新验证码の基础招式', pos=(380,43))passdefTextctrl(self):'文本控件初始化'#学号输入框self.text = wx.TextCtrl(self.panel,value='请输入学号...', style=wx.TE_PROCESS_ENTER)        self.text.SetForegroundColour('#888888')#密码输入框self.text1 = wx.TextCtrl(self.panel,value='password', style=wx.TE_PASSWORD)        self.text1.SetForegroundColour('#888888')#学段选择框self.Choice_Listbox()#self.text2 = wx.TextCtrl(self.panel, value='2017-2018-2')#self.text2.SetForegroundColour('#888888')#注释提示self.Comment()#验证码输入框self.code_text = wx.TextCtrl(self.panel,value='请输入验证码...', style=wx.TE_PROCESS_ENTER)        self.code_text.SetForegroundColour('#888888')defGrades_List(self):'列表控件初始化'self.list = wx.ListCtrl(self.panel, id=-1, pos=(10,75), size=(989,500), style=wx.LC_REPORT)# , size=(895,500), self.CreateHeader()#创建列表标签self.list.InsertItem(0,"请填充信息.")#初始化列表内容为‘请填充信息.’  defCreateHeader(self):'列表标签设定'self.list.InsertColumn(0,"学号", format=wx.LIST_FORMAT_LEFT, width=80)        self.list.InsertColumn(1,"姓名", format=wx.LIST_FORMAT_CENTER, width=50)        self.list.InsertColumn(2,"开课学期", format=wx.LIST_FORMAT_CENTER, width=100)        self.list.InsertColumn(3,"课程名称", format=wx.LIST_FORMAT_LEFT, width=230)        self.list.InsertColumn(4,"总成绩", format=wx.LIST_FORMAT_CENTER, width=50)        self.list.InsertColumn(5,"课程性质", format=wx.LIST_FORMAT_CENTER, width=100)        self.list.InsertColumn(6,"课程类别", format=wx.LIST_FORMAT_CENTER, width=75)        self.list.InsertColumn(7,"学时", format=wx.LIST_FORMAT_CENTER, width=50)        self.list.InsertColumn(8,"学分", format=wx.LIST_FORMAT_CENTER, width=50)        self.list.InsertColumn(9,"考试性质", format=wx.LIST_FORMAT_CENTER, width=75)        self.list.InsertColumn(10,"补重学期", format=wx.LIST_FORMAT_CENTER, width=100)defButtons(self):'按钮控件初始化'self.button = wxbutton.GenButton(self.panel,-1,'查询成绩')        self.code_button = wxbutton.GenButton(self.panel,-1,'获取/刷新验证码')        self.help_button = wxbutton.GenButton(self.panel,-1,'帮助')defBoxsizer(self):'容器设定'box = wx.BoxSizer(wx.HORIZONTAL)#放置水平的box sizerbox.Add(self.text,0, wx.ALL,10)#水平方向伸展时不改变尺寸box.Add(self.text1,0, wx.ALL,10)#box.Add(self.text2, 0, wx.ALL, 10)box.Add(self.code_button,0, wx.ALL,10)        box.Add(self.code_text,0, wx.ALL,10)        box.Add(self.listbox,0, wx.ALL,10)        box.Add(self.button,0, wx.ALL,10)        box.Add(self.help_button,0, wx.ALL,10)        self.panel.SetSizerAndFit(box)defEvent_deal(self):'程序事件处理'self.Bind(wx.EVT_BUTTON, self.Fresh_Code, self.code_button)        self.Bind(wx.EVT_TEXT_ENTER, self.Fresh_Code, self.text)        self.Bind(wx.EVT_BUTTON, self.OnRefresh, self.button)        self.Bind(wx.EVT_TEXT_ENTER, self.OnRefresh, self.code_text)        self.Bind(wx.EVT_TEXT, self.modify_colour, self.text)        self.Bind(wx.EVT_TEXT, self.modify_colour, self.text1)#self.Bind(wx.EVT_TEXT, self.modify_colour, self.text2)self.Bind(wx.EVT_TEXT, self.modify_colour, self.code_text)        self.Bind(wx.EVT_BUTTON, self.OnClick_Help, self.help_button)        self.Bind(wx.EVT_LIST_COL_CLICK, self.sort_by_column, self.list)#左键单击某列标题,正序重排列表self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.sort_by_column_reversed, self.list)#右键单击某列标题,逆序重排列表defmodify_colour(self, event):'文本框有输入时改变其文本颜色'event.GetEventObject().SetForegroundColour('#2F4F4F')defFresh_Code(self, event):'刷新验证码'self.cookies = get_code_in_file()        self.image_show()#self.bmp.SetBitmap(wx.Bitmap(wx.Image('code.jpg', wx.BITMAP_TYPE_JPEG)))defimage_show(self):'验证码显示'image = wx.Image('code.jpg', wx.BITMAP_TYPE_JPEG)        temp = image.ConvertToBitmap()#size = temp.GetWidth(), temp.GetHeight()self.bmp = wx.StaticBitmap(parent=self.panel, bitmap=temp, pos=(420,40))defOnRefresh(self,event):'多线程刷新列表'try:            self.get_data()except:            print("用户未登录,成绩无法获取!")ifself.data:            thread.start_new_thread(self.SetData,(0, ))else:            self.OnClick()defget_data(self):'获取成绩数据'index = self.listbox.GetSelection()        temp = [self.text.GetValue(), self.text1.GetValue(), self.list1[index]]        verifycode_ = self.code_text.GetValue()        self.data = parser_data(verifycode_, self.cookies, temp[0], temp[1], temp[-1])ifself.data == []:            self.OnClick()defSetData(self, pos):'将数据插入到列表,不同成绩段显示不同颜色'self.list.ClearAll()        self.CreateHeader()foreachinself.data:            pos = self.list.InsertItem(pos+1,each[0])foriinrange(1,11):                self.list.SetItem(pos,i,each[i])            grade = each[4]try:ifint(grade) <60:                    self.list.SetItemBackgroundColour(pos, (255,0,0))#挂科显示为红色elifint(grade) <=61:                    self.list.SetItemBackgroundColour(pos, (255,99,71))#60到61为浅红elifint(grade) <=74:                    self.list.SetItemBackgroundColour(pos, (238,221,130))#62到74为黄elifint(grade) <=84:                    self.list.SetItemBackgroundColour(pos, (152,251,152))#75到84为浅绿elifint(grade) <=100:                    self.list.SetItemBackgroundColour(pos, (124,252,0))#85到100为绿except:passifgrade =='不及格':                self.list.SetItemBackgroundColour(pos, (255,0,0))#挂科显示为红色elifgrade =='及格'andeach[3] !='军事技能训练':                self.list.SetItemBackgroundColour(pos, (255,99,71))#及格为浅红elifgrade =='中':                self.list.SetItemBackgroundColour(pos, (238,221,130))#中为黄elifgrade =='良'oreach[3] =='军事技能训练':                self.list.SetItemBackgroundColour(pos, (152,251,152))#良为浅绿,军训特殊,大部分为及格,显示为浅绿elifgrade =='优':                self.list.SetItemBackgroundColour(pos, (124,252,0))#优为绿defsort_by_column(self, listevent):'按指定标签正序排序列表'num = listevent.GetColumn()#with open('data.json', 'w') as f:#    f.write(json.dumps(self.data, ensure_ascii=False, indent=4, sort_keys=False))self.data = sorted(self.data, key=itemgetter(num))        self.SetData(pos=0)defsort_by_column_reversed(self, listevent):'按指定标签逆序排序列表'num = listevent.GetColumn()        self.data = sorted(self.data, key=itemgetter(num), reverse=True)        self.SetData(pos=0)defOnClick(self):'切换到窗体TipsFrame'self.UpdateUI(1)defOnClick_Help(self, event):'切换到窗体HelpFrame'self.UpdateUI(2)classTipsFrame(wx.Frame):def__init__(        self, parent=None, id=0, title='来自王Sの温馨提示~', pos=wx.DefaultPosition,size=wx.DefaultSize,        style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.RESIZE_BORDER), UpdateUI=None    ):wx.Frame.__init__(self, parent, id,title=title, size=size, pos=pos, style=style)                self.UpdateUI = UpdateUI        self.InitUI()# 绘制UI界面self.Center()defInitUI(self):#绘制面板panel = wx.Panel(self)#图标设定self.Software_Icon()#图片插入image = wx.Image('hnust(black).ico', wx.BITMAP_TYPE_ICO)        temp = image.ConvertToBitmap()#size = temp.GetWidth(), temp.GetHeight()self.bmp = wx.StaticBitmap(parent=panel, bitmap=temp)#静态文本self.text = wx.StaticText(panel, label='--请检查你输入的学号、密码或验证码是否正确\n--学号输入完成记得按回车键\n--请核对你所查询的学段\n--或者刷新验证码试试吧~', pos=(10,10))        self.text.SetForegroundColour('#FF4500')#确定按钮button = wxbutton.GenButton(panel,0,'好的~')#控件排版box = wx.BoxSizer(wx.VERTICAL)        box.Add(self.bmp,0, wx.CENTER,50)        box.Add(self.text,0, wx.CENTER,50)        box.Add(button,0, wx.CENTER,50)        panel.SetSizerAndFit(box)#事件处理self.Bind(wx.EVT_BUTTON, self.OnClick, button)defSoftware_Icon(self):icon = wx.Icon('hnust(black).ico', wx.BITMAP_TYPE_ICO)        self.SetIcon(icon)defOnClick(self,event):'关闭该窗口'self.Close()classHelpFrame(wx.Frame):def__init__(        self, parent=None, id=1, title='帮助信息', pos=wx.DefaultPosition,size=wx.DefaultSize,        style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.RESIZE_BORDER), UpdateUI=None    ):wx.Frame.__init__(self,parent, id, title, size=size, pos=pos, style=style)                self.UpdateUI = UpdateUI        self.InitUI()        self.Center()defInitUI(self):panel = wx.Panel(self)        self.Software_Icon()                image = wx.Image('hnust(black).ico', wx.BITMAP_TYPE_ICO)        temp = image.ConvertToBitmap()#size = temp.GetWidth(), temp.GetHeight()self.bmp = wx.StaticBitmap(parent=panel, bitmap=temp)                self.text = wx.StaticText(panel, label='四步走:\n  ①输入学号按回车获取验证码\n  ②第二框输入教务网密码\n  ⑤输入验证码按回车或点击"查询成绩"即可\n', pos=(10,10))        self.text.SetForegroundColour('#FF4500')        button = wxbutton.GenButton(panel,1,'Get!')                box = wx.BoxSizer(wx.VERTICAL)        box.Add(self.bmp,0, wx.CENTER,50)        box.Add(self.text,0, wx.CENTER,50)        box.Add(button,0, wx.CENTER,50)        panel.SetSizerAndFit(box)                self.Bind(wx.EVT_BUTTON, self.OnClick, button)defSoftware_Icon(self):icon = wx.Icon('hnust(black).ico', wx.BITMAP_TYPE_ICO)        self.SetIcon(icon)defOnClick(self, event):'关闭该窗口'self.Close()

这些Codes真是按照下面的思维导图所写得的,也完全符合开头所述的Frame基本结构。

主要运用的就是我上面写的那几个基本控件还有方法。

功能设计在代码中亦有介绍,敬请查看。

思维导图

你可能感兴趣的:([Python]wxpython中Frame所用到的主要控件以及方法)