Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 选择时带有弹出窗口的Listview_Python 3.x_Kivy_Kivy Language - Fatal编程技术网

Python 3.x 选择时带有弹出窗口的Listview

Python 3.x 选择时带有弹出窗口的Listview,python-3.x,kivy,kivy-language,Python 3.x,Kivy,Kivy Language,我正在尝试制作一个列表视图,在该视图中,所选按钮会根据所选的列表按钮生成一个具有不同信息的弹出窗口。有什么建议吗?谢谢自Kivy 1.10.0版以来,ListView已被弃用。在下面的示例中,我们使用Recycleview 例子 main.py 试验电压(千伏) #:kivy 1.10.0 : 标题:“弹出消息框” 大小提示:无,无 尺码:400400 盒子布局: 方向:“垂直” 标签: 文本:app.root.rv_layout.selected_值 按钮: 大小提示:1,0.2 文字:“OK

我正在尝试制作一个列表视图,在该视图中,所选按钮会根据所选的列表按钮生成一个具有不同信息的弹出窗口。有什么建议吗?谢谢

自Kivy 1.10.0版以来,ListView已被弃用。在下面的示例中,我们使用Recycleview

例子 main.py 试验电压(千伏)
#:kivy 1.10.0
:
标题:“弹出消息框”
大小提示:无,无
尺码:400400
盒子布局:
方向:“垂直”
标签:
文本:app.root.rv_layout.selected_值
按钮:
大小提示:1,0.2
文字:“OK”
新闻界:
根目录
:
#绘制背景以指示选择
在以下情况之前:
颜色:
rgba:(0.0,0.9,0.1,0.3)
矩形:
pos:self.pos
大小:self.size
:
rv_布局:布局
viewclass:“SelectableButton”
可选择的可循环利用布局:
id:布局
默认大小:无,dp(56)
默认大小提示:0.1,无
尺寸提示:无
高度:自身最小高度
方向:“垂直”
输出
自Kivy 1.10.0版以来,ListView已被弃用。在下面的示例中,我们使用Recycleview

例子 main.py 试验电压(千伏)
#:kivy 1.10.0
:
标题:“弹出消息框”
大小提示:无,无
尺码:400400
盒子布局:
方向:“垂直”
标签:
文本:app.root.rv_layout.selected_值
按钮:
大小提示:1,0.2
文字:“OK”
新闻界:
根目录
:
#绘制背景以指示选择
在以下情况之前:
颜色:
rgba:(0.0,0.9,0.1,0.3)
矩形:
pos:self.pos
大小:self.size
:
rv_布局:布局
viewclass:“SelectableButton”
可选择的可循环利用布局:
id:布局
默认大小:无,dp(56)
默认大小提示:0.1,无
尺寸提示:无
高度:自身最小高度
方向:“垂直”
输出

最好解释一下您尝试了什么,以及它是如何失败的,但是如果您还没有任何东西,我建议您使用RecycleView而不是ListView(我们不赞成使用RecycleView,支持RecycleView),它更简单、更灵活、更高效。最好解释一下您尝试了什么,以及它是如何失败的,但是如果您还没有任何东西,我建议使用RecycleView而不是ListView(我们不赞成使用ListView,支持RecycleView),它更简单、更灵活、更高效。
from kivy.app import App
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.button import Button
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.popup import Popup
from kivy.properties import ListProperty, StringProperty, ObjectProperty


class MessageBox(Popup):

    def popup_dismiss(self):
        self.dismiss()


class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):
    """ Adds selection and focus behaviour to the view. """
    selected_value = StringProperty('')
    btn_info = ListProperty(['Button 0 Text', 'Button 1 Text', 'Button 2 Text'])


class SelectableButton(RecycleDataViewBehavior, Button):
    """ Add selection support to the Label """
    index = None

    def refresh_view_attrs(self, rv, index, data):
        """ Catch and handle the view changes """
        self.index = index
        return super(SelectableButton, self).refresh_view_attrs(rv, index, data)

    def on_press(self):
        self.parent.selected_value = 'Selected: {}'.format(self.parent.btn_info[int(self.id)])

    def on_release(self):
        MessageBox().open()


class RV(RecycleView):
    rv_layout = ObjectProperty(None)

    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.data = [{'text': "Button " + str(x), 'id': str(x)} for x in range(3)]


class TestApp(App):
    title = "RecycleView Button Popup Demo"

    def build(self):
        return RV()


if __name__ == "__main__":
    TestApp().run()
#:kivy 1.10.0

<MessageBox>:
    title: 'Popup Message Box'
    size_hint: None, None
    size: 400, 400

    BoxLayout:
        orientation: 'vertical'
        Label:
            text: app.root.rv_layout.selected_value
        Button:
            size_hint: 1, 0.2
            text: 'OK'
            on_press:
                root.dismiss()

<SelectableButton>:
    # Draw a background to indicate selection
    canvas.before:
        Color:
            rgba: (0.0, 0.9, 0.1, 0.3)
        Rectangle:
            pos: self.pos
            size: self.size

<RV>:
    rv_layout: layout
    viewclass: 'SelectableButton'
    SelectableRecycleBoxLayout:
        id: layout
        default_size: None, dp(56)
        default_size_hint: 0.1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: "vertical"