让显示更改为kivy应用程序

时间:2014-01-26 16:05:07

标签: python kivy

当我运行应用程序时,加载.kv布局,我输入必要的信息并调用set_info但屏幕没有更改为set_info()中的布局,我没有做过任何gui编程,所以我要去试图弄清楚这一点。在文本框中输入信息后,如何才能更改显示?

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()

如果名称 ==“主要”:     偏移()。运行()

<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()

1 个答案:

答案 0 :(得分:0)

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

这就是问题所在。你创建了这个root,并为其添加了布局,但是你实际上从未将root添加到任何内容中,因此它不会显示。

解决方案是将您的root添加到 显示的窗口小部件树的现有窗口小部件中。