>>>>>##使⽤说明3>>>>>>>###class PageThree(wx.Panel):
def__init__(lf, parent):
wx.Panel.__init__(lf, parent)
colour = [(160, 255, 204), (153, 204, 255), (151, 253, 225), ]
lf.SetBackgroundColour(colour[2])
<3 = wx.StaticText(lf, -1, "查看结果", (355, 45),
(100, -1), wx.ALIGN_CENTER)
font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)
<3.SetFont(font)
3.结合matplotlib
Matplotlib的常见对象Figure,FigureCanvas,Axes,给出最简单的例程:
scores = [89, 98, 70, 80, 60, 78, 85, 90]
t_score = numpy.arange(1, len(scores) + 1, 1)
s_score = numpy.array(scores)
lf.figure_score = Figure()
lf.figure_score.t_figheight(3.6)
lf.figure_score.t_figwidth(7.8)
lf.axes_score = lf.figure_score.add_subplot(111)
#画图
lf.axes_score.plot(t_score, s_score, 'ro', t_score, s_score, 'k')
lf.axes_score.t_title(u'My Scores')
lf.id(True)
俄罗斯男女lf.axes_score.t_xlabel('T')
lf.axes_score.t_ylabel('score')
#在lf.CenterPanel上显⽰
cannvas = FigureCanvas(lf.CenterPanel, -1, lf.figure_score)
补充关于wx.Font
wx.Font 对象确定⼀个⽂本的外观。可以在其他有⽂本显⽰的控件⽐如 TextCtrl,Button,Label 通过 tFont(Font对象)来指明。
其构造函数如下:
wx.Font(pointSize,family,style,weight,underline,faceName,encoding)
参数说明
illa illa
pointSize pointSize是字体的以磅为单位的整数尺⼨。
family family⽤于快速指定⼀个字体⽽⽆需知道该字体的实际的名字.字体的准确选择依赖于系统和具体可⽤的字体.你所得到的精确的字体将依赖于你的系统。字体类别如下:wx.DECORATIVE:⼀个正式的,⽼的英⽂样式字体。 wx.DEFAULT:style style参数指明字体的是否倾斜,它的值有:wx.NORMAL,wx.SLANT,wx.ITALIC
weight weight参数指明字体的醒⽬程度,他的值有:wx.NORMAL,wx.LIGHT,wx.BOLD
underline underline参数仅⼯作在Windows系统下,如果取值为True,则加下划线,Fal为⽆下划线。
faceName faceName参数指定字体名。
encoding encoding参数允许你在⼏个编码中选择⼀个,它映射内部的字符和字本显⽰字符。编码不是Unicode编码,只是⽤于wxPython的不同的8位编码。⼤多数情况你可以使⽤默认编码。
4.完整源码
import wx
import numpy
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class Example(wx.Frame):
def__init__(lf, parent, title):
super(Example, lf).__init__(parent, title=title)
lf.Init_Panel()
lf.Init_Box()
lf.Init_Left()
lf.Init_Center()
lf.Init_Right()
# 将三个垂直盒⼦添加到垂直盒⼦
lf.Boxh1.Add(lf.LeftPanel,proportion = 1, border = 2,flag = wx.ALL | wx.EXPAND)
lf.Boxh1.Add(lf.CenterPanel, proportion=4, border=2, flag=wx.ALL | wx.EXPAND)
lf.Boxh1.Add(lf.RightPanel, proportion=1, border=2, flag=wx.ALL | wx.EXPAND)
#将垂直盒⼦和主框架关联
lf.SetSizer(lf.Boxh1)
#显⽰主框架
lf.Show()
#创建三个⾯板
def Init_Panel(lf):
lf.LeftPanel = wx.Panel(lf)
lf.CenterPanel = wx.Panel(lf)
lf.RightPanel = wx.Panel(lf)
#创建四个盒⼦
#三个垂直盒⼦、⼀个⽔平盒⼦
def Init_Box(lf):
#三个垂直盒⼦
lf.Boxv1 = wx.BoxSizer(wx.VERTICAL)
lf.Boxv2 = wx.BoxSizer(wx.VERTICAL)
lf.Boxv3 = wx.BoxSizer(wx.VERTICAL)
#⼀个⽔平盒⼦
lf.Boxh1 = wx.BoxSizer(wx.HORIZONTAL)
def Init_Left(lf):
# 创建⼀个wx.StaticBox对象。
# 声明⼀个wx.StaticBoxSizer与创建的wx.StaticBox对象作为其参数。
nm = wx.StaticBox(lf.LeftPanel, -1, '参数输⼊')
nmSizer = wx.StaticBoxSizer(nm, wx.VERTICAL)
# 构建静态⽂本框
modelname = wx.StaticText(lf.LeftPanel, -1, "模块名称")
# 在StaticBoxSizer添加⽂本框
nmSizer.Add(modelname, 1, wx.EXPAND | wx.ALL, 1)
# 创建下拉框
lf.languages = ['NXP', 'MSP430', 'SMT32']
# 在StaticBoxSizer盒⼦添加下拉框
nmSizer.bo1, 1, wx.EXPAND | wx.ALL, 1)
# 构建静态⽂本框
kunomodeltype = wx.StaticText(lf.LeftPanel, -1, "模块型号")
# 在StaticBoxSizer添加⽂本框
nmSizer.Add(modeltype, 1, wx.EXPAND | wx.ALL, 1)
# 创建下拉框
lf.languages = ['0x123a', '0x3333', '0x1232']
# 在StaticBoxSizer添加下拉框
nmSizer.bo2, 1, wx.EXPAND | wx.ALL, 1)
# 在垂直盒⼦添加StaticBoxSizer
lf.Boxv1.Add(nmSizer,0, wx.EXPAND | wx.ALL,10)
#创建RadioButton
lblList = ['线性⽹', '单环⽹', '双环⽹','双⽹冗余']
lf.rbox = wx.RadioBox(lf.LeftPanel, label='组⽹类型', choices=lblList, majorDimension=4,style=wx.RA_SPECIFY_ROWS)
# 在垂直盒⼦添加RadioButton
lf.Boxv1.Add(lf.rbox,0, wx.EXPAND | wx.ALL,10)
# 创建⼀个wx.StaticBox对象。
# 声明⼀个wx.StaticBoxSizer与创建的wx.StaticBox对象作为其参数。
nm1 = wx.StaticBox(lf.LeftPanel, -1, '⽇志信息')
nmSizer1 = wx.StaticBoxSizer(nm1, wx.VERTICAL)
# 创建⽂本域
lf.multiText = wx.TextCtrl(lf.LeftPanel, -1, style=wx.TE_MULTILINE) # 创建⼀个⽂本控件
lf.multiText.SetInrtionPoint(0) # 设置插⼊点
nmSizer1.Add(lf.multiText, 1, wx.EXPAND | wx.ALL, 10)
# 在垂直盒⼦⾥添加StaticBoxSizer盒⼦
lf.Boxv1.Add(nmSizer1, 1, wx.EXPAND | wx.ALL, 10)
#把垂直盒⼦与LeftPanel关联起来
lf.LeftPanel.SetSizer(lf.Boxv1)
def Init_Center(lf):
lf.CenterPanel.SetBackgroundColour('white')
scores = [89, 98, 70, 80, 60, 78, 85, 90]
t_score = numpy.arange(1, len(scores) + 1, 1)
s_score = numpy.array(scores)
dualitylf.figure_score = Figure()
lf.figure_score.t_figheight(3.6)
lf.figure_score.t_figwidth(7.8)
lf.axes_score = lf.figure_score.add_subplot(111)
#画图
lf.axes_score.plot(t_score, s_score, 'ro', t_score, s_score, 'k')
lf.axes_score.t_title(u'My Scores')
lf.id(True)
lf.axes_score.t_xlabel('T')
lf.axes_score.t_ylabel('score')
#在lf.CenterPanel上显⽰
cannvas = FigureCanvas(lf.CenterPanel, -1, lf.figure_score)
lf.Boxv2.Add(cannvas, 1, wx.EXPAND | wx.ALL, 10)
#创建notebook
nb = wx.Notebook(lf.CenterPanel, style=wx.NB_FIXEDWIDTH)
page1 = PageOne(nb)
page2 = PageTwo(nb)
page3 = PageThree(nb)
#在notebook中添加⾯板,第⼀个参数是⾯板,第⼆个参数是标签
nb.AddPage(page1, "使⽤说明")
nb.AddPage(page2, "选择检索")
nb.AddPage(page3, "查看结果")
lf.Boxv2.Add(nb, 1, wx.EXPAND | wx.ALL, 10)
lf.CenterPanel.SetSizer(lf.Boxv2)
def Init_Right(lf):
lf._btn1 = wx.Button(lf.RightPanel, label=u'Diag', size=(50, 50))
lf.Boxv3.Add(lf._btn1, 0, wx.EXPAND | wx.ALL, 10)
lf._btn2 = wx.Button(lf.RightPanel, label=u'Trend', size=(50, 50))
lf.Boxv3.Add(lf._btn2, 0, wx.EXPAND | wx.ALL, 10)
lf._btn3 = wx.Button(lf.RightPanel, label=u'About', size=(50, 50))
lf.Boxv3.Add(lf._btn3, 0, wx.EXPAND | wx.ALL, 10)
lf.RightPanel.SetSizer(lf.Boxv3)
#本质:创建了三个⾯板
考试书
>>>>>##使⽤说明1>>>>>>>### class PageOne(wx.Panel):def__init__(lf, parent):
wx.Panel.__init__(lf, parent)
colour = [(160, 255, 204), (153, 204, 255), (151, 253, 225), ]
lf.SetBackgroundColour(colour[0])
<1 = wx.StaticText(lf, -1, "使⽤说明", (355, 45),
(100, -1), wx.ALIGN_CENTER)nequal
font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)
<1.SetFont(font)
liting
>>>>>##使⽤说明2>>>>>>>### class PageTwo(wx.Panel):def__init__(lf, parent):
wx.Panel.__init__(lf, parent)
colour = [(160, 255, 204), (153, 204, 255), (151, 253, 225), ]
lf.SetBackgroundColour(colour[1])
<2 = wx.StaticText(lf, -1, "选择检索", (355, 45),
(100, -1), wx.ALIGN_CENTER)
font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)
<2.SetFont(font)
>>>>>##使⽤说明3>>>>>>>### class PageThree(wx.Panel):def__init__(lf, parent):
joynerwx.Panel.__init__(lf, parent)
colour = [(160, 255, 204), (153, 204, 255), (151, 253, 225), ]
lf.SetBackgroundColour(colour[2])
<3 = wx.StaticText(lf, -1, "查看结果", (355, 45),
(100, -1), wx.ALIGN_CENTER)
font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)
<3.SetFont(font)
app = wx.App()
斑秃原因
Example(None, title='布局实践')
app.MainLoop()
View Code