【问题标题】:How to display kivy panels vertically in a .kv file?如何在 .kv 文件中垂直显示 kivy 面板?
【发布时间】:2018-12-31 23:17:33
【问题描述】:

我有我的 kivy 文件和我的 python 文件。我可以显示我的面板并在单击时显示它们的内容,但面板是水平方向的。我希望这些选项卡垂直显示。我尝试过使用

orientation: "vertical" 

这不是我检查过但从未真正找到答案的重复问题。代码如下:

    <SampBoxLayout>:
orientation: "vertical"
padding: 10
spacing: 10


BoxLayout:
    orientation: "vertical"
    height: 30

    BoxLayout:
        orientation: "vertical"
        size_hint_x: .25
        size_hint_y: .25

        TabbedPanel:
            do_default_tab: False
            size: 5, 5

            TabbedPanelItem:
                text: "Home"
                Label:
                    text: "Content of Home"
            TabbedPanelItem:
                text: "Browse"
                Label:
                    text: "Content of Browse"
            TabbedPanelItem:
                text: "Radio"
                Label:
                    text: "Content of Radio"
            TabbedPanelItem:
                text: "Made for You"
                Label:
                    text: "Content of Made For You"
            TabbedPanelItem:
                text: "Recently Played"
                Label:
                    text: "Content of Recently Played"
            TabbedPanelItem:
                text: "Favorite Songs"
                Label:
                    text: "Content of Recent Songs"
            TabbedPanelItem:
                text: "Albums"
                Label:
                    text: "Content of Albums"
            TabbedPanelItem:
                text: "Artists"
                Label:
                    text: "Content of Artists"
            TabbedPanelItem:
                text: "Stations"
                Label:
                    text: "Content of Stations"
            TabbedPanelItem:
                text: "Local Files"
                Label:
                    text: "Content of Local Files"
            TabbedPanelItem:
                text: "Videos"
                Label:
                    text: "Content of Videos"
            TabbedPanelItem:
                text: "Videos"
                Label:
                    text: "Content of Videos"
            TabbedPanelItem:
                text: "Podcasts"
                Label:
                    text: "Content of Podc

【问题讨论】:

  • 澄清一下,我需要垂直列出面板项目。了解kivy的人应该知道我的意思。而不是几个 TabbedPanels 我希望 TabbedPanelItems 是垂直的
  • 在这种情况下,如果代码是必要且强制性的,因为您指出: ... 面板是水平定向的。我希望这些选项卡垂直显示。我尝试过使用:`orientation:"vertical"`,也就是说,你尝试了一些看起来正确但没有成功的方法,所以如果没有代码,你的问题就跑题了:"why is这段代码不工作吗?”。总之,如果您需要帮助,请提供minimal reproducible example
  • 您的代码可能不是您提出问题的必要条件,但我们需要提供合理的答案。请发帖MCVE
  • @eyllanesc,谢谢你的信息!!
  • 不,您甚至不需要代码来回答问题,但在这里我将编辑问题并显示代码

标签: python kivy


【解决方案1】:

如果我了解您想要什么,您需要将tab_pos 属性添加到您的TabbedPanel,例如:

    TabbedPanel:
        do_default_tab: False
        tab_pos: 'left_top'

除非您对它们进行其他操作,否则您不需要所有这些 BoxLayout 项目。

【讨论】:

  • 这可以解决我对一个问题提出的要求。它不会更改文本方向,因此文本是横向的。我该如何解决这个问题?
  • 这是TabbedPanel 的一个功能。它可能可以定制为您想要的方式,但这将是很多工作。在左侧布局一列 ToggleButtons 并在右侧布局单个内容(可能是 AnchorLayout)可能会更容易。然后对切换按钮进行编程以切换内容。
猜你喜欢
  • 1970-01-01
  • 2014-06-17
  • 1970-01-01
  • 2021-10-05
  • 1970-01-01
  • 1970-01-01
  • 2021-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多