Kivy不输出纯文本,仅输出对象位置 [英] Kivy Does Not Output Plain Text, Only Object Location

查看:96
本文介绍了Kivy不输出纯文本,仅输出对象位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图在Kivy中创建一个非常基本的文本编辑器.所以我解决了文本不显示的问题(通过lambda).但是,一个新的错误即将出现.保存.我想自动保存为纯文本文件.但是,我当前的代码仅保存实际文本输入的对象(是否是指针?).谢谢大家!

So I was trying to create a very basic text editor in Kivy. So I had got around the issue of text not showing up (via lambda). However, a new error appeared on the horizon; saving. I want to save automatically to a plain txt file. However, my current code only save an object (is it a pointer?) of the actual text input. Thank you all, SO!

    import kivy
    import os
    kivy.require('1.10.1') # replace with your current kivy version !
    from kivy.app import App
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.textinput import TextInput
    from kivy.uix.label import Label
    from kivy.clock import Clock
    from kivy.uix.button import Button
    from kivy.lang import Builder

    class ColdKivyApp(App): # I actually used to call it Zone but changed it to Cold cause it's cold outside ;)
            def build(self):
                    f = BoxLayout(orientation='vertical')
                    txt = TextInput(multiline=True, cursor_blink=True, background_color=(1,1,1,1))
                    f.add_widget(txt)
                    txtstr = str(txt)
                    Clock.schedule_once(lambda *args: setattr(txt, "focus", True))
                    with open('testtxt.txt', 'w') as txtwriter:
                        txtwriter.write("" + txtstr)
                        txtwriter.close()
                    return f

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

拼写

推荐答案

将代码中的txtstr = str(txt)替换为txtstr = txt.text.

这篇关于Kivy不输出纯文本,仅输出对象位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆