2014-01-26 35 views
0

當我運行應用程序時,.kv佈局被加載,我輸入必要的信息和set_info被調用但屏幕不改變在set_info()的佈局,我沒有做過任何gui編程之前,所以我正在圍繞試圖弄清楚這一點。我在文本框中輸入信息後如何獲取顯示內容?讓顯示器來改變kivy應用

class GetInformation(AnchorLayout): 
    initial_bet = ObjectProperty() 
    initial_odds = ObjectProperty() 

    def set_info(self): 
     self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None) 
     self.layout.bind(minimum_height=self.layout.setter('height')) 
     for k in offset_lay((Decimal(self.initial_bet.text),Decimal(self.initial_odds.text)): 
      btn = Button(text=str(k[0]), size_hint_y=None, height=40) 
      self.layout.add_widget(btn) 
     root = ScrollView(size_hint=(1, .80), size=(600, 600)) 
     root.add_widget(self.layout) 
     return root 



class AccountDetailsTextInput(TextInput): 
    next = ObjectProperty() 
    def _keyboard_on_key_down(self, window, keycode, text, modifiers): 

     if keycode[0] == 9: # 9 is the keycode for tab 
      self.next.focus = True 
     elif keycode[0] == 13: # 13 is the keycode for enter 
      self.parent.parent.set_odds() 
     else: 
      super(AccountDetailsTextInput, self)._keyboard_on_key_down(
       window, keycode, text, modifiers) 



class Offset(App): 
    def build(self): 
     return GetInformation() 

如果 == 「主要」: 偏移()的run()

<GetInformation>: 
anchor_y: "top" 
anchor_x: "right" 
initial_bet:bet 
initial_odds:odds 
GridLayout: 
    cols: 2 
    row_default_height: "40dp" 
    row_force_default: True 
    spacing: "10dp" 
    padding: "10dp" 
    Label: 
     markup:True 
     font_size: '32sp' 
     text: "[color=ff3333][/color] [color=3333ff][b]Enter your initial stake:[/color]" 
    AccountDetailsTextInput: 
     id:bet 
     next:odds 
    Label: 
     markup:True 
     font_size: '32sp' 
     text: "[color=ff3333][/color] [color=3333ff][b]Enter your initial odds:[/color]" 
    AccountDetailsTextInput: 
     id:odds 
     next: bet 
    Button: 
     size_hint_y: None 
     #id: set_odd 
     height: "40dp" 
     text: "Calculate" 
     background_color: .7, .7, 1, 1 
     halign: 'center' 
     valign: 'middle' 
     on_press: root.set_info() 

回答

0
root = ScrollView(size_hint=(1, .80), size=(600, 600)) 
root.add_widget(self.layout) 
return root 

該位是問題。你這root,並添加布局到它,但你從來沒有真正加入到root任何所以它不會顯示出來。

解決方案是將您的root添加到一些現有的小部件,部分顯示的小部件樹。