简体   繁体   English

Kivy中Tabbed Panel内的小部件

[英]Widgets inside Tabbed Panel in Kivy

I'm new to designing in kivy and I'm trying to display a listview, inputbox and label inside a Tab panel but it's showing empty panel. 我刚开始在kivy设计,我试图在Tab面板中显示listview,inputbox和label,但它显示为空面板。 I'm not sure where is my mistake. 我不确定我的错误在哪里。 I want to do a simple search of users by just typing the username in the inputbox then the listview will automatically update the records inside the listview. 我想通过在输入框中输入用户名来对用户进行简单搜索,然后listview将自动更新listview中的记录。

I'm using kivy 1.10.0 and python 3.6 我正在使用kivy 1.10.0和python 3.6

Here is my code in kivy file: 这是我在kivy文件中的代码:

<AdminMainScreen@Screen>:#===================MAIN SCREEN=========================
txt_search: txt_search
view_user_list: view_user_list

BoxLayout:
    size_hint_y: 1
    size_hint_x: 1

    canvas:
        Color:
            rgb: .132, .232, .249
        Rectangle:
            size: self.size

    TabbedPanel:
        do_default_tab: False

        TabbedPanelItem:
            text:"1st Tab"
            Label:
                text: "Content of Admin Panel"

        TabbedPanelItem:
            text:"2nd Tab"
            Label:
                text: "Content of Second Panel"

        TabbedPanelItem:
            text:"Manage Users"
            BoxLayout:
                size_hint_y: .2
                size_hint_x: 1
                orientation: 'horizontal'

                Label:
                    text: "Search User"
                    size_hint_x: .25
                    spacing: .2, .2

                TextInput:
                    id: txt_search
                    text: ""
                    size_hint_x: .3
                    spacing: .2, .2
            Label:
                id: lbl_search
                size_hint_y:None
                height: 10
                text: ""

            ListView:
                color: [0,0,0]
                id: view_user_list
                size_hint_x: 1
                size_hint_y: .8
                item_strings: []
                adapters:
                    ListAdapter(data=[], cls = ListItemButton)

I don't think that having multiple widgets in a TabbedPanelItem is allowed, there is only one child - content . 我不认为在TabbedPanelItem中有多个小部件是允许的,只有一个子content So just put an extra Layout and everything you want in the tab inside that one layout: 所以只需在一个布局中的选项卡中添加一个额外的布局和所需的一切:

BoxLayout: # The only child of panel item
    size_hint_y: 1
    size_hint_x: 1
    orientation: 'horizontal'

    BoxLayout:
        size_hint_y: 0.2
        size_hint_x: 1
        orientation: 'horizontal'

        Label:
            text: "Search User"
            size_hint_x: .25
            spacing: .2, .2

        TextInput:
            id: txt_searh
            text: ""
            size_hint_x: .3
            spacing: .2, .2
    Label:
        id: lbl_search
        size_hint_y:None
              ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM