各个窗口的应用

    xiaoxiao2022-06-30  60

    import wx class MDIFrame(wx.MDIParentFrame): def __init__(self): wx.MDIParentFrame.__init__(self,None,-1,'mdi',size = (200,300)) menubar = wx.MenuBar() menu = wx.Menu() menu.Append(1000,'new') menu.Append(1001,'quit') menubar.Append(menu,'file') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.OnNew, id = 1000) self.Bind(wx.EVT_MENU, self.OnQuit,id = 1001) def OnNew(self,event): win = wx.MDIChildFrame(self,-1,'child',size = (100,300)) panel = wx.Panel(self,-1) button = wx.Button(pane,-1,'open',pos = (0,0),size = (30,50)) win.Show() def OnQuit(self,event): self.Close(True) if __name__ == '__main__': app = wx.PySimpleApp() frame = MDIFrame() frame.Show() app.MainLoop()

    #-*- coding:utf-8 -*- import wx import os from wx.tools.Editra.src.ed_main import OnAbout from wx import ID_OPEN class MniFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,'mini',pos = (100,100),size = (400,300),style = wx.DEFAULT_FRAME_STYLE | wx.CLOSE_BOX) pannel = wx.Panel(self,-1,size = (200,300)) menubar = wx.MenuBar() menu = wx.Menu() menu.Append(1001,'about') menubar.Append(menu,'help(&h)') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.OnAbout, id=1001) btn = wx.Button(pannel,-1,'MessageDialog',pos = (20,20),size = (100,30)) self.Bind(wx.EVT_BUTTON,self.OnMessageDialog,btn) btn1 = wx.Button(pannel,-1,'MessageDialog',pos = (20,60),size = (100,30)) self.Bind(wx.EVT_BUTTON,self.OnTextInput,btn1) btn2 = wx.Button(pannel,-1,'MessageDialog',pos = (20,100),size = (100,30)) self.Bind(wx.EVT_BUTTON,self.OnOpen,btn2) def OnOpen(self,event): filter = "Paint files(*.py)|*.py|All files(*.*)|*.*" #dlg = wx.FileDialog(self,"Save paint as ...", os.getcwd(), style = wx.SAVE | wx.OVERWRITE_PROMPT, wildcard = filter) dlg = wx.FileDialog(self,u"打开文件", os.getcwd(), style = wx.OPEN, wildcard = filter) if dlg.ShowModal()==wx.ID_OK: print 'path = ' +dlg.GetPath() dlg.Destroy() def OnMessageDialog(self,event): #提示对话框例子 dlg = wx.MessageDialog(self,u'是否退出',u"quit",wx.YES_NO|wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: print 'quit' dlg.Destroy() def OnTextInput(self,event): #文本输入对话框的输入例子 dlg = wx.TextEntryDialog(self,u"请输入文本",u"文本框",'',style = wx.OK|wx.CANCEL) if dlg.ShowModal() == wx.ID_OK: print '--:'+dlg.GetValue() dlg.Destroy() def OnAbout(self,e): MyDialog(self,'test').Show() class MyDialog(wx.Dialog): def __init__(self,parant,title): wx.Dialog.__init__(self,parant,-1,title,size = (100,100)) self.panel = wx.Panel(self,-1) self.button = wx.Button(self.panel,1002,'OK',pos = (10,10),size = (50,30)) self.Bind(wx.EVT_BUTTON,self.OnClose,self.button) self.Show() def OnClose(self,e): #不要有自己调用自己的方法 print '==' self.Close(True) if __name__ == '__main__': app = wx.PySimpleApp() frame = MniFrame() frame.Show() app.MainLoop() #-*- coding:utf-8 -*- import wx import os from wx.tools.Editra.src.ed_main import OnAbout from wx import ID_OPEN class MniFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,'mini',pos = (100,100),size = (400,300),style = wx.DEFAULT_FRAME_STYLE | wx.CLOSE_BOX) pannel = wx.Panel(self,-1,size = (200,300)) menubar = wx.MenuBar() menu = wx.Menu() menu.Append(1001,'about') menubar.Append(menu,'help(&h)') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.OnAbout, id=1001) btn = wx.Button(pannel,-1,'MessageDialog',pos = (20,20),size = (100,30)) self.Bind(wx.EVT_BUTTON,self.OnMessageDialog,btn) btn1 = wx.Button(pannel,-1,'MessageDialog',pos = (20,60),size = (100,30)) self.Bind(wx.EVT_BUTTON,self.OnTextInput,btn1) btn2 = wx.Button(pannel,-1,'MessageDialog',pos = (20,100),size = (100,30)) self.Bind(wx.EVT_BUTTON,self.OnOpen,btn2) def OnOpen(self,event): filter = "Paint files(*.py)|*.py|All files(*.*)|*.*" #dlg = wx.FileDialog(self,"Save paint as ...", os.getcwd(), style = wx.SAVE | wx.OVERWRITE_PROMPT, wildcard = filter) dlg = wx.FileDialog(self,u"打开文件", os.getcwd(), style = wx.OPEN, wildcard = filter) if dlg.ShowModal()==wx.ID_OK: print 'path = ' +dlg.GetPath() dlg.Destroy() def OnMessageDialog(self,event): #提示对话框例子 dlg = wx.MessageDialog(self,u'是否退出',u"quit",wx.YES_NO|wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: print 'quit' dlg.Destroy() def OnTextInput(self,event): #文本输入对话框的输入例子 dlg = wx.TextEntryDialog(self,u"请输入文本",u"文本框",'',style = wx.OK|wx.CANCEL) if dlg.ShowModal() == wx.ID_OK: print '--:'+dlg.GetValue() dlg.Destroy() def OnAbout(self,e): MyDialog(self,'test').Show() class MyDialog(wx.Dialog): def __init__(self,parant,title): wx.Dialog.__init__(self,parant,-1,title,size = (100,100)) self.panel = wx.Panel(self,-1) self.button = wx.Button(self.panel,1002,'OK',pos = (10,10),size = (50,30)) self.Bind(wx.EVT_BUTTON,self.OnClose,self.button) self.Show() def OnClose(self,e): #不要有自己调用自己的方法 print '==' self.Close(True) if __name__ == '__main__': app = wx.PySimpleApp() frame = MniFrame() frame.Show() app.MainLoop()

    转载请注明原文地址: https://ju.6miu.com/read-1125882.html

    最新回复(0)