wxpython初学者(三) 之flexgirdsizer,TextEntryDialog,SingleChoiceDialog
#!/usr/binpython#coding:utf-8#flexgirdsizerimport wxclass Example(wx.Frame):def __init__(self,parent,title):super(Example,self).__init__(parent,title=title,size=(300,250))
·
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#flexgirdsizer
import wx
class Example(wx.Frame):
def __init__(self,parent,title):
super(Example,self).__init__(parent,title=title,size=(300,250))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
hbox = wx.BoxSizer(wx.HORIZONTAL)
fgs = wx.FlexGridSizer(3,2,9,25)
title = wx.StaticText(panel,label = 'Tilte :')
author = wx.StaticText(panel,label = 'Author')
review = wx.StaticText(panel,label = 'Review')
tc1 = wx.TextCtrl(panel)
tc2 = wx.TextCtrl(panel)
tc3 = wx.TextCtrl(panel,style =wx.TE_MULTILINE)
fgs.AddMany([(title),(tc1,1,wx.EXPAND),(author),(tc2,1,wx.EXPAND),(review,1,wx.EXPAND),(tc3,1,wx.EXPAND)])
fgs.AddGrowableRow(2,1)
fgs.AddGrowableCol(1,1)
hbox.Add(fgs,proportion=1,flag=wx.ALL | wx.EXPAND,border = 15 )
panel.SetSizer(hbox)
if __name__ == '__main__':
app = wx.App()
Example(None,title='FlexGridSizer')
app.MainLoop()</span>
<span style="font-size:18px;">#!/usr/bin python
#coding:utf-8
#TextEntryDialog
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, u'测试面板Panel', size = (600, 300))
#创建面板
panel = wx.Panel(self)
#在Panel上添加Button
button = wx.Button(panel, label = u'关闭', pos = (150, 60), size = (100, 60))
#绑定单击事件
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
#消息对话框
def OnCloseMe(self, event):
dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Close(True)
dlg.Destroy()
# def OnCloseMe(self, event):
# dlg = wx.TextEntryDialog(None, u"请在下面文本框中输入内容:", u"文本输入框标题", u"默认内容")
# if dlg.ShowModal() == wx.ID_OK:
# message = dlg.GetValue() #获取文本框中输入的值
# dlg_tip = wx.MessageDialog(None, message, u"标题信息", wx.OK | wx.ICON_INFORMATION)
# if dlg_tip.ShowModal() == wx.ID_OK:
# self.Close(True)
# dlg_tip.Destroy()
# dlg.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame(parent = None, id = -1)
frame.Show()
app.MainLoop()</span>
<span style="font-size:18px;">import wx
class MyFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'testpanel',size = (600, 300))
panel = wx.Panel(self)
button = wx.Button(panel,label = 'close',pos= (150,60),size = (100,60) )
self.Bind(wx.EVT_BUTTON,self.OnCloseMe,button)
# def OnCloseMe():
# dlg = wx.MessageDialog(None,"messagetest","title",wx.YES_NO | wx.ICON_QUESTION)
# if dlg.ShowModal() == wx.ID_YES:
# self.Close(True)
# dlg.Destroy()
def OnCloseMe(self,event):
dlg = wx.TextEntryDialog(None,"please input context","texttitle","default")
if dlg.ShowModal() == wx.ID_OK:
message = dlg.GetValue()
dlg_tip = wx.MessageDialog(None,message,"titlemessage",wx.OK | wx.ICON_INFORMATION)
if dlg_tip.ShowModal() == wx.ID_OK:
self.Close(True)
dlg_tip.Destroy()
dlg.Destroy()
# def OnCloseMe(self,event):
# dlg = wx.SingleChoiceDialog(None,"fruit","salefruit",['apple','blala','tomato'])
# if dlg.ShowModal() == wx.ID_OK:
# message = dlg.GetStringSelection()
# dlg_tip = wx.MessageDialog(None,message,"titlemessage",wx.ID_OK | wx.ICON_INFORMATION)
# if dlg_tip.ShowModal() == wx.ID_OK:
# self.Close(True)
# dlg_tip.Destroy()
# dlg.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame(parent = None ,id =-1)
frame .Show()
app.MainLoop()</span>
#!/usr/bin python
#coding:utf-8
#boxsizer
import wx
class Example(wx.Frame):
def __init__(self,*args,**kwargs):
super(Example,self).__init__(*args,**kwargs)
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
st1 = wx.StaticText(panel,label="file")
hbox1.Add(st1,proportion=0,flag=wx.RIGHT,border=10)
tc = wx.TextCtrl(panel)
hbox1.Add(tc,proportion=2)
vbox.Add(hbox1,flag=wx.EXPAND | wx.LEFT |wx.RIGHT |wx.TOP,border = 10)
vbox.Add((-1,10))
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
st2 = wx.StaticText(panel,label="context")
hbox2.Add(st2,proportion=0)
vbox.Add(hbox2,flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,border =10)
# hbox3= wx.BoxSizer(wx.HORIZONTAL)
# tc2 = wx.TextCtrl(panel,style=wx.TE_MULTILINE)
# hbox3.Add(tc2,proportion=1,flag=wx.EXPAND)
# vbox.Add(hbox3,proportion=1,flag=wx.LEFT | wx.RIGHT | wx.EXPAND,border=10)
panel.SetSizer(vbox)
def main():
app = wx.App()
Example(None)
app.MainLoop()
if __name__ == '__main__':
main()
#coding:utf-8
import wx
class InsertFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame With Button',
size=(300,100))
##创建画板
panel = wx.Panel(self)
##将按钮添加到画板
button = wx.Button(panel,label="Close",pos=(125,10),size=(50,50))
##绑定按钮的单击事件
self.Bind(wx.EVT_BUTTON,self.OnCloseMe,button)
##绑定窗口的关闭事件
self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
def OnCloseMe(self,event):
self.Close(True)
def OnCloseWindow(self,event):
self.Destroy()
if __name__ =="__main__":
app = wx.PySimpleApp()
frame = InsertFrame(parent=None,id=-1)
frame.Show()
app.MainLoop()
#!/usr/bin python
#coding:utf-8
import wx
import wx.py.images
class ToolbarFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Toolbars',size = (300,200))
panel = wx.Panel(self)
panel.SetBackgroundColour('White')
statusBar = self.CreateStatusBar()
toolbar = self.CreateToolBar()
toolbar.AddSimpleTool(wx.NewId(),wx.py.images.getPyBitmap(),"New","Long help for 'New'")
toolbar.AddSimpleTool(wx.NewId(),wx.py.images.getPyBitmap(),"Edit","Long help for 'Edit'")
toolbar.Realize()
menuBar = wx.MenuBar()
menu1 = wx.Menu()
menuBar.Append(menu1, "&File")
# menu1.Append(wx.NewId(),"du","xing")
menu_item1 = menu1.Append(wx.NewId(),"&du","xing")
menu1.Append(wx.NewId(),"shuai","ming")
self.Bind(wx.EVT_MENU,self.OnCloseMe,menu_item1)
menu2 = wx.Menu()
menu_item2 = menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
menu2.Append(wx.NewId(), "C&ut","")
menu2.Append(wx.NewId(),"Paste","")
menu2.AppendSeparator()
menu2.Append(wx.NewId(),"&Options...","Display Options")
menuBar.Append(menu2,"&Edit")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU,self.OnCloseMe,menu_item2)
def OnCloseMe(self,event):
dlg = wx.MessageDialog(None,"MessageDialog", "titlemessage", wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Close(True)
dlg.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ToolbarFrame(parent = None,id = -1)
frame.Show()
app.MainLoop()
更多推荐
已为社区贡献1条内容
所有评论(0)