简体   繁体   English

如何在没有.kv 文件的 Kivy TEXTINPUT 中添加行号?

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

I am trying to create a simple notepad for android.我正在尝试为 android 创建一个简单的记事本。 How can I add line numbers to the Kivy's TextInput()?如何将行号添加到 Kivy 的 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.我是 kivy 的新手,我确实注意到使用 KV 文件,因为有时让我感到困惑,我更喜欢“python”风格。

I take a look on kivy API and I found my own way of doing line numbers.我看了一下 kivy API 并找到了自己的行号方式。 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.因为 CodeInput 是从 TextInput 继承的,所以您可以替换它并且也可以正常工作。

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.现在我将继续在我的github上更新它,因为它变得有点大(600 多行),因为我试图将它保存在一个文件中。

Preview:预习:

预习

Perhaps this may help you: https://github.com/griloHBG/TextInputLineNumber也许这可以帮助你: https://github.com/griloHBG/TextInputLineNumber

It uses KV language (which is very nice), but could use as a base to develop something python-only.它使用 KV 语言(非常好),但可以用作基础来开发仅 python 的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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