Kivy文本编辑器输入未显示

时间:2019-02-15 05:34:42

标签: python python-3.x text kivy

不幸的是,我在kivy和Python 3中遇到了一个错误。我还没有从Google那里找到一个灵魂。我想至少输入文本,但它不会显示。只是文字本身。谢谢您的时间!

import kivy
kivy.require('1.10.1') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label

class ColdKivyApp(App):
    def build(self):
        f = FloatLayout()
        label = Label(text="Cold") #I acutally orginally called it Zone unitil I changed it into Cold cause it's really cold now
        f.add_widget(label)
        txt = TextInput(text='', focus=True, multiline=True, cursor_blink=True, background_color=(1,1,1,1))
        f.add_widget(txt)
        return f

if __name__ == '__main__':
    ColdKivyApp().run()

1 个答案:

答案 0 :(得分:0)

在构造函数中设置焦点时,TextInput中似乎有一个错误,一种解决方法是在通过Clock显示窗口之后立即设置焦点:

import kivy
kivy.require('1.10.1') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.clock import Clock

class ColdKivyApp(App):
    def build(self):
        f = FloatLayout()
        label = Label(text="Cold") 
        f.add_widget(label)
        txt = TextInput(multiline=True, cursor_blink=True, background_color=(1,1,1,1))
        f.add_widget(txt)
        Clock.schedule_once(lambda *args: setattr(txt, "focus", True))
        return f

if __name__ == '__main__':
    ColdKivyApp().run()