2015-07-20 50 views
2

我想在屏幕上放一些文本框和按鈕,但似乎不起作用。代碼中的任何建議或問題?運行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

一切都可能有,只是每個上面都其他因爲默認情況下屏幕將其子項填充自己。

嘗試下面的內容,它使用一個boxlayout,它應該將其子女放在不同的地方。

屏幕: 名稱: '屏幕截圖1' 的BoxLayout: 方向: '垂直' 標籤: 標記:真 文字: '馬尼什' 的TextInput: 文字: '嗨Kivy' 按鈕: 文字: '轉到屏幕1' on_press: _screen_manager.current = '屏蔽1' 按鈕: 文本: '轉到屏幕2' on_press: root.login() _screen_manager.current ='畫面2

+0

謝謝,這工作完美 – pkm

相關問題