今天学习了常用的控件
StaticText文本类:
对于所有的UI工具来说,最基本的任务就是在屏幕上绘制纯文本。在wxPython中,可以使用wx.StaticText类完成。使用wx.StaticText能够改变文本的对齐方式,字体和颜色等。wx.StaticText类的构造函数的语法如下:
wx.StaticText(parent,id,label,pos=wx.DefaultPosition,size=wx.DefaultSize,
style=0,name="staticText")
参数 | 说明 |
---|---|
parent | 父窗口部件 |
id | 标识符。使用-1可以自动创建一个唯一的标识 |
label | 显示在静态控件中的文本内容 |
pos | 一个wx.Point或一个Python元组,它是窗口部件的位置 |
size | 一个wx.Size或一个Python元组,它是窗口部件的尺寸 |
style | 样式标记 |
name | 对象的名字 |
事例:
用wx.StaticText输出Python之禅
import wx
class one(wx.Frame):
def __init__(self,parent,id):
wx.frame.__init__(self,parent,id,label='Python',pos=(100,100),size=(600,400))
panel=wx.Panel(self) #创建画板
#创建标题,并设置字体
title=wx.StaticText(panel,label='The Zen of Python, by Tim Peters',pos=(100,20))
font=wx.Font(16,wx.DEFAULT,wx.FONTSTYLE_NORMAL,wx.NORMAL)
title.SetFont(font)
#创建文本
wx.StaricText(panel, label='Beautiful is better than ugly.',pos=(50,50))
wx.StaricText(panel, label='Explicit is better than implicit.',pos=(50,70))
wx.StaricText(panel, label='Simple is better than complex.',pos=(50,90))
wx.StaricText(panel, label='Complex is better than complicated.',pos=(50,110))
wx.StaricText(panel, label='Flat is better than nested.',pos=(50,130))
wx.StaricText(panel, label='Sparse is better than dense.',pos=(50,150))
wx.StaricText(panel, label='Readability counts.',pos=(50,170))
wx.StaricText(panel, label='Special cases are not special enough to break the rules.',pos=(50,190))
wx.StaricText(panel, label='Although practicality beats purity.',pos=(50,210))
wx.StaricText(panel, label='Errors should never pass silently.',pos=(50,230))
wx.StaricText(panel, label='Unless explicitly silenced.',pos=(50,250))
wx.StaricText(panel, label='In the face of ambiguity, refuse the temptation to guess.',pos=(50,270))
wx.StaricText(panel, label='There should be one-- and preferably only one --obvious way to do it.',pos=(50,290))
wx.StaricText(panel, label='Although that way may not be obvious at first unless you are Dutch.',pos=(50,310))
wx.StaricText(panel, label='Now is better than never.',pos=(50,330))
wx.StaricText(panel, label='Although never is often better than *right* now.',pos=(50,350))
wx.StaricText(panel, label='If the implementation is hard to explain, it is a bad idea.',pos=(50,370))
wx.StaricText(panel, label='If the implementation is easy to explain, it may be a good idea.',pos=(50,390))
wx.StaricText(panel, label='Namespaces are one honking great idea -- let us do more of those!',pos=(50,410))
if __name__=='__main__':
app=wx.App() #初始化应用
frame=one(parent=None,id=-1)
frame.Show()
app.MainLoop()
但是这个好像不能输出结果。。。