繁体   English   中英

如何使 kivy 可见背景颜色的树视图标签

[英]how to make the treeview label in kivy visible background color

我正在尝试使我的树视图标签可见,我的意思是当我执行树视图并运行和展开树时,我可以看到问题是其他 UI 元素(如文本输入)是可见的,我不希望那样,我可以'如果它位于文本输入上方,则进行选择

from kivy.uix.treeview import TreeViewLabel,TreeView, TreeViewNode
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
class Accounting(App):
    def build(self):
        tree=TreeView(hide_root=True)
        root=tree.add_node(TreeViewLabel(text='choose'))
        for a in range(100):
            tree.add_node(TreeViewLabel(text=str(a),even_color=(0,0,0,0)),root)
        # if you try here to change the color visibility the numbers will appears but you can't select it
        textinput=TextInput(hint_text='textinput',foreground_color=(1,1,1,1),background_color=(0,0,0,0))
    
        layout=BoxLayout(orientation='vertical')
        layout.add_widget(tree)
        layout.add_widget(textinput)

        return layout

Accounting().run()

尝试这样的事情。 没有必要隐藏文本字段,但对我来说看起来更好

from kivy.app import App
from kivy.uix.treeview import TreeViewLabel
from kivy.lang import Builder

KV = """
FloatLayout:
    TextInput:
        id: text_field
        size_hint_y: None
        pos_hint: {'center_y': 0.5}
        height: self.minimum_height
        
    ScrollView:
        TreeView:
            id: tv
            size_hint_y: None
            height: self.minimum_height
            hide_root: True
            on_node_expand: app.hide(True)
            on_node_collapse: app.hide(False)
"""


class Accounting(App):
    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        root = self.root.ids.tv.add_node(TreeViewLabel(text="Choose"))
        for a in range(100):
            self.root.ids.tv.add_node(TreeViewLabel(text=str(a)), root)

    def hide(self, hide):
        if hide:
            self.root.ids.text_field.foreground_color = (1, 1, 1, 1)
            self.root.ids.text_field.background_color = (0, 0, 0, 0)
        else:
            self.root.ids.text_field.foreground_color = (0, 0, 0, 1)
            self.root.ids.text_field.background_color = (1, 1, 1, 1)


Accounting().run()

暂无
暂无

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

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