Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 208
Parvat . R Avatar asked Oct 30 '25 21:10

Parvat . R


2 Answers

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).

Preview:

preview

like image 99
ASI Avatar answered Nov 01 '25 10:11

ASI


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.

like image 34
griloHBG Avatar answered Nov 01 '25 12:11

griloHBG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!