乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      wxpython 開發(fā)的記事本

       天才白癡書館 2015-04-13

      wxpython 開發(fā)的記事本

      前幾天無聊,在網(wǎng)上看別人用wxpython寫了一個(gè)東西非常的好玩,感覺python開發(fā)軟件也不錯(cuò),開發(fā)效率比較高,于是自己也學(xué)了點(diǎn)wxpython的前面一點(diǎn)內(nèi)容,自己寫了個(gè)例子玩玩:

      #encoding=utf-8
      #!/usr/bin/python
      # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
      # See LICENSE for details.

      import os
      import sys
      import wx
      ID_OPEN = 101
      ID_EXIT = 110
      ID_SAVE = 111
      ID_BUTTON = 112

      class MainWindow(wx.Frame):
          """ We simply derive a new class of Frame. """
          def __init__(self, parent, id, title):
              wx.Frame.__init__(self, parent, id, title, size=(500,100))
              self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
              self.CreateStatusBar()
              filemenu  = wx.Menu()
              filemenu.Append(ID_OPEN,"打開文件","open file")
              filemenu.AppendSeparator()
              filemenu.Append(ID_SAVE,"保存文件"," save file")
              filemenu.AppendSeparator()
              filemenu.Append(ID_EXIT,"退出","exit")
              menuBar = wx.MenuBar()
              menuBar.Append(filemenu,"文件")
              self.SetMenuBar(menuBar)
              wx.EVT_MENU(self,ID_OPEN,self.open)
              wx.EVT_MENU(self,ID_EXIT,self.exit)
              wx.EVT_MENU(self,ID_SAVE,self.save)
              self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
              self.buttons = []
             
      #        for i in range(0,6):
      #            self.buttons.append(wx.Button(self,ID_BUTTON+i,"Button &"+'i'))   
      #            self.sizer2.Add(self.buttons[i],1,wx.EXPAND)
              self.sizer = wx.BoxSizer(wx.VERTICAL)
              self.sizer.Add(self.control,1,wx.EXPAND)
              self.sizer.Add(self.sizer2,0,wx.EXPAND)
              self.SetSizer(self.sizer)
              self.SetAutoLayout(1)
              self.sizer.Fit(self)
             
              self.Show(True)
             
          def exit(self,e):
              '''用戶退出窗口'''
              self.Close(True)
             
          def open(self,e):
              '''打開文件 '''
              self.dirname = ''
              dlg = wx.FileDialog(self,"chose a file",self.dirname,"","*.*",wx.OPEN)
             
              if dlg.ShowModal() == wx.ID_OK:
                  self.filename = dlg.GetFilename()
                  self.dirname = dlg.GetDirectory()
                  f = open(os.path.join(self.dirname,self.filename),'r')
                  self.control.SetValue(f.read())
                  f.close()
              dlg.Destroy()
             
          def save(self,e):
              '''保存文件'''
              try:
                  f = open(os.path.join(self.dirname,self.filename),'w')
              except AttributeError:
                  print '文件不存在'
                  sys.exit(0)
                 
              content = self.control.GetValue()
              try:
                  f.write(content)
              except UnboundLocalError:
                  print '文件不存在'
                  sys.exit(0)
              finally:
                  f.close()
                         
         
      app = wx.PySimpleApp()
      frame=MainWindow(None,-1, 'Small editor')
      app.MainLoop()

      直接運(yùn)行就可以生成一個(gè)窗口,有打開和關(guān)閉的功能,其他的功能沒有完善,有興趣的朋友可以學(xué)習(xí)下,和大家一起分享你的成果吧! 

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多