【问题标题】:How can I move listview below MDToolbar如何将列表视图移动到 MDToolbar 下方
【发布时间】:2020-12-26 18:00:58
【问题描述】:

正如您在屏幕截图中看到的那样,Listview 的顶部项目与 mdtoolbar 混合在一起。我想在 MDtoolbar 下方显示。我尝试在 kv 代码中更改 MDList 中的 pos_hint 属性。但它不动。我怎样才能把它移到下面?有没有办法把它贴在工具栏下面没有pos_hint

.py 文件

class ListApp(Screen):
    built = BooleanProperty(False)

    def build(self):
        if self.built:
            return
        self.built = True
        self.popup = Popup(title='Calculating Stoploss', content=Image(source='please_wait.gif'))
        self.popup.open()
        threading.Thread(target=self.actual_build).start()

    def actual_build(self):
        end = datetime.today().date()
        start = end

        i = 0
        fl = len(file.index)
        try:
            for index in range(fl):

                for index in range(1):
                    columnSeriesObj2 = file.iloc[:, 0]

                    df = web.DataReader(columnSeriesObj2.values[i],'yahoo', start, end,retry_count=3)
                    print(df.head())
                    Objname = file.iloc[:, 2]
                    columnSeriesObj = df.iloc[:, 3]
                    columnSeriesObj1 = file.iloc[:, 1]
                    ObjStoploss = file.iloc[:, 3]

                    cp = iter(columnSeriesObj.values)
                    pp = iter(columnSeriesObj1.values)
                    pp1 = next(pp)
                    cp1 = columnSeriesObj.values[0]
                    sl = columnSeriesObj1.values[i] - (columnSeriesObj1.values[i] * (ObjStoploss.values[i]/100))

                    if cp1 <= sl:
                        Clock.schedule_once(partial(self.add_loss, Objname.values[i], str(cp1), str(sl)))
                        i=i+1
                    else:
                        Clock.schedule_once(partial(self.add_profit, Objname.values[i], str(cp1), str(sl)))
                        i=i+1
        except ConnectionAbortedError:
            print("Check your Internet connection")
        except ConnectionRefusedError:
            print("Check your Internet connection")
        except ConnectionError:
            print("Check your Internet connection")
        except ConnectionResetError:
            print("Check your Internet connection")
        except TimeoutError:
            print("Timeout!!!!...Check your Internet connection")
        except KeyError:
            pass

        except:
            pass
            # print("Something went wrong")
        print("Done")
        self.popup.dismiss()

    def add_loss(self, name, close_price, stop_loss, dt):
            image = ImageLeftWidget(source='loss.png')
            items = ThreeLineAvatarIconListItem(text="Alert sale " + name, secondary_text='Close price: '+close_price,
                                                tertiary_text='Stoploss: ' + stop_loss)
            items.add_widget(image)
            self.ids.list_view.add_widget(items)

    def add_profit(self, name, close_price, stop_loss, dt):
            image = ImageLeftWidget(source='profit.jpg')
            items = ThreeLineAvatarIconListItem(text="Chill " + name,
                                                secondary_text='Close price: ' + close_price,
                                                tertiary_text='Stoploss: ' + stop_loss)
            items.add_widget(image)

            self.ids.list_view.add_widget(items)



# class WindowsManager(ScreenManager):
#     pass

sm = ScreenManager()
sm.add_widget(ListApp(name='Stoploss_ip'))



class run1(MDApp):

    def build(self):
        kv = Builder.load_file("stopl.kv")
        return kv

if __name__ == "__main__":
    run1().run()

.kv 文件

<ListApp>:
    name: 'Stoploss_ip'
    orientation:'vertical'
    on_enter:root.build()
    MDToolbar:
        title:'Stoploss'
        type: "top"
        md_bg_color:229/255,33/255,101/255,1
        left_action_items: [["back button.png", lambda x: root.back()]]
        pos_hint: {'top':1.0}
        elevation:8

    ScrollView:
        MDList:
            id: list_view
            pos_hint: {'y':3.0}

这里是 stoploss.csv file的链接

这是截图

【问题讨论】:

    标签: python python-3.x kivy kivy-language kivymd


    【解决方案1】:
    MDBoxLayout:
        orientation: "vertical"
    
        Toolbar:
    
        ScrollView:
    

    【讨论】:

    • 嘿,@Xyanight!这是完整的答案吗?能否请您检查代码是否正确并添加一些解释?
    • @Vivi。不,它只是一个结构。不是完整的代码。他只是在给我指出正确的方向。如果想要完整的代码..请参阅我的问题和在 kivy 代码中 -> 只需添加 MDBoxLayout.
    • @Rushabh Patil,问题是即使你理解了答案,其他人阅读这篇文章希望解决类似的问题,但可能有点不同,或者比你更缺乏经验的人,可能不明白。通常鼓励简短的解释。也就是说,由于我对这个话题一无所知,所以我将把它留给你们来决定:)
    • @Xyanight。我认为薇薇是对的。我正在用简短的解释更新你的答案
    猜你喜欢
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    相关资源
    最近更新 更多