Python implements the method of removing the row number before the code, and python removes the code before

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.