Python implements the method of removing the row number before the code, and python removes the code before
This example describes how to remove the row number before the code in Python. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows: #-*-coding: UTF-8 -*-
Import wx
Class MainWindow (wx. Frame ):
Def _ init _ (self, parent, id ):
Wx. Frame. _ init _ (self, parent, id,
U'python gadgets that remove the row number before the code-wxPython-Develop by yanxy ')
Self. textBox = wx. TextCtrl (self, 1, style = wx. TE_MULTILINE, size = (600,600 ))
Self. butOK = wx. Button (self, label = u "Remove row number ")
Self. butLeft = wx. Button (self, label = u "remove one character on the left ")
Self. Bind (wx. EVT_BUTTON, self. CutLineNum, self. butOK)
Self. Bind (wx. EVT_BUTTON, self. CutLeftChar, self. butLeft)
Self. Bind (wx. EVT_CLOSE, self. OnCloseWindow)
Self. sizer = wx. BoxSizer (wx. HORIZONTAL)
Self. sizer. Add (self. textBox, 1, wx. EXPAND)
Self. sizer. Add (self. butOK)
Self. sizer. Add (self. butLeft)
Self. SetSizer (self. sizer)
Self. SetAutoLayout (1)
Self. sizer. Fit (self)
Self. Show (True)
Def OnCloseWindow (self, event ):
Self. Destroy ()
Def CutLineNum (self, event ):
MultiStr = unicode (self. textBox. GetValue (). splitlines (1)
OutStr = u''
For singleStr in multiStr:
SingleStr = singleStr. lstrip ()
I = 0
For charStr in singleStr:
If charStr. isdigit ():
I + = 1
Elif I> 0:
SingleStr = singleStr [I:]
Break
Else:
Break
OutStr + = singleStr
Self. textBox. SetValue (outStr)
Def CutLeftChar (self, event ):
OutStr = u''
MultiStr = unicode (self. textBox. GetValue (). splitlines (1)
For singleStr in multiStr:
SingleStr = singleStr [1:]
OutStr + = singleStr
Self. textBox. SetValue (outStr)
If _ name _ = '_ main __':
App = wx. PySimpleApp ()
Frame = MainWindow (parent = None, id =-1)
App. MainLoop ()
Del app
I hope this article will help you with Python programming.