简体   繁体   中英

How to add line numbers in Kivy TEXTINPUT without .kv file?

I am trying to create a simple notepad for android. How can I add line numbers to the Kivy's TextInput()? My code is

from kivy.app import App

from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout

class Text(TextInput):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.hint_text = "Your text here"

class NotePad(App):
    def build(self):
        box = BoxLayout()
        text = Text()
        box.add_widget(text)
        return box

I want to add the line numbers. How can I do that?

Is late for you base on time stamp, but I found it my self in the same problem like you and I assume are and other on the same both. I'm new in kivy and I do note use KV files because some times is confusing me, I like more of "python" style.

I take a look on kivy API and I found my own way of doing line numbers. Is not the best one or the smarter one, but is doing the job.

Because CodeInput is inherit from TextInput you can replace it and will work as well.

I updated the code to solve errors and I added comments and futures. For now one I will continue to update it on my github because is become a little bigger (600+ lines) because I try to keep it in one file.

Preview:

预习

Perhaps this may help you: https://github.com/griloHBG/TextInputLineNumber

It uses KV language (which is very nice), but could use as a base to develop something python-only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM