Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

python - Is it possible to have multiple Text Inputs printed to a Label with Kivy?

I want to make a "notes board" app where you can type in multiple inputs and be able to drag them around in the label, is this possible using Kivy, or is it not meant for such purposes?

So far I am able to type one string into the label, but when I try to move it around, the TextInput and button move to the middle of the screen. I am not sure if I am using Scatter correctly. I am also using two BoxLayouts because I was having a hard time resizing/ anchoring the TextInput and Button with others

import kivy
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.scatter import Scatter
from kivy.uix.widget import Widget


class MyLayout(Widget):
    txt_input = ObjectProperty(None)
    txt_output = ObjectProperty(None)

    def press(self):
        todo = self.txt_input.text

        # update label
        self.txt_output.text = todo


class MainApp(App):
    def build(self):
        return MyLayout()
        

if __name__ == "__main__":
    MainApp().run()

--

#:kivy 2.0.0

<MyLayout>:

    txt_input: txt_input
    txt_output: txt_output

    BoxLayout:
        orientation: 'vertical'
        size: root.width, root.height
        Scatter:
            Label:
                id: txt_output
                font_size: 150
        BoxLayout:
            cols: 2
            TextInput:
                pos: (0,0)
                id: txt_input
                size_hint_x: .8
                size_hint_y: None
                font_size: 150
            Button:
                pos: (1278,0)
                size_hint_x: .2
                size_hint_y: None
                text: "add"
                on_press: root.press()

Thanks in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...