屏幕内的小部件(按钮,输入文本等)不起作用

时间:2015-07-20 17:32:22

标签: python kivy

我试图在屏幕内放置一些文本框和按钮,但似乎它不起作用。代码中的任何建议或问题?当运行main.py时,textinput和第一个按钮和标签不存在

Phone.kv

<Phone>:
    orientation: 'vertical'
    ScreenManager:
        size_hint: 1, 1
        id: _screen_manager
        Screen:
            name: 'screen1'
            Label:
                markup: True
                text: 'manish'
            TextInput:
                text: 'Hi Kivy'
            Button:
                text: 'Go to Screen 1'
                on_press:
                    _screen_manager.current = 'screen1'
            Button:
                text: 'Go to Screen 2'
                on_press:
                    root.login()
                    _screen_manager.current = 'screen2'

        Screen:
            name: 'screen2'
            GridLayout:
                cols: 3
                padding: 50
                Button:
                    text: "1"

main.py

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
import time

class Phone(FloatLayout):
    def login(self):
        print "before"
        time.sleep(2)
        print "after"

class PhoneApp(App):
    def build(self):
        return Phone()

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

1 个答案:

答案 0 :(得分:1)

所有东西都可能存在,只是所有东西都在彼此之上,因为默认情况下,Screen会让孩子自己填充。

尝试以下内容,使用boxlayout将其子项放在不同的位置。

屏幕:     名称:&#39; screen1&#39;     BoxLayout的:         方向:&#39;垂直&#39;         标签:             加价:是的             文字:&#39; manish&#39;         的TextInput:             文字:&#39;嗨Kivy&#39;         按钮:             文字:&#39;转到屏幕1&#39;             on_press:                 _screen_manager.current =&#39; screen1&#39;         按钮:             文字:&#39;转到屏幕2&#39;             on_press:                 root.login()                 _screen_manager.current =&#39; screen2&#39;