#-*- encoding:UTF-8 -*-
import wx
app = wx.App()
win = wx.Frame(None, title="My Notebook", size=(410, 335))
panel = wx.Panel(win)
openButton = wx.Button(panel, label="Open")
saveButton = wx.Button(panel, label="Save")
filepathTxt = wx.TextCtrl(panel)
contentTxt = wx.TextCtrl(panel, style=wx.TE_MULTILINE)
#默认水平, 放置 文件路径文本框 打开按钮 保存按钮
# proportion : 占总体的 几分之1
# flag : expand 扩展
hbox = wx.BoxSizer()
hbox.Add(filepathTxt, proportion=1, flag=wx.EXPAND)
hbox.Add(openButton, proportion=0, flag=wx.LEFT, border=5)
hbox.Add(saveButton, proportion=0, flag=wx.LEFT, border=5)
#垂直,
bbox = wx.BoxSizer(wx.VERTICAL)
bbox.Add(hbox, proportion=0, flag=wx.EXPAND|wx.ALL, border=5)
bbox.Add(contentTxt, proportion=1,flag=wx.EXPAND|wx.LEFT|wx.BOTTOM|wx.RIGHT,border=5)
panel.SetSizer(bbox)
win.Show()
app.MainLoop()
通过组件的 Bind(func) 绑定事件处理函数
举例:
#-*- encoding:UTF-8 -*-
import wx
def openFileEventHandle(evt) :
filepath = filepathTxt.GetValue()
fopen = open(filepath)
content = fopen.read()
fopen.close()
contentTxt.SetValue(content)
def saveFileEventHandle(evt) :
filepath = filepathTxt.GetValue()
fopen = open(filepath, "w")
content = contentTxt.GetValue()
fopen.write(content)
fopen.close()
app = wx.App()
win = wx.Frame(None, title="My Notebook", size=(410, 335))
panel = wx.Panel(win)
openButton = wx.Button(panel, label="Open")
saveButton = wx.Button(panel, label="Save")
filepathTxt = wx.TextCtrl(panel)
contentTxt = wx.TextCtrl(panel, style=wx.TE_MULTILINE)
#绑定事件
openButton.Bind(wx.EVT_BUTTON, openFileEventHandle)
saveButton.Bind(wx.EVT_BUTTON, saveFileEventHandle)
#默认水平, 放置 文件路径文本框 打开按钮 保存按钮
# proportion : 占总体的 几分之1
# flag : expand 扩展
hbox = wx.BoxSizer()
hbox.Add(filepathTxt, proportion=1, flag=wx.EXPAND)
hbox.Add(openButton, proportion=0, flag=wx.LEFT, border=5)
hbox.Add(saveButton, proportion=0, flag=wx.LEFT, border=5)
#垂直,
bbox = wx.BoxSizer(wx.VERTICAL)
bbox.Add(hbox, proportion=0, flag=wx.EXPAND|wx.ALL, border=5)
bbox.Add(contentTxt, proportion=1,flag=wx.EXPAND|wx.LEFT|wx.BOTTOM|wx.RIGHT,border=5)
panel.SetSizer(bbox)
win.Show()
app.MainLoop()