亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Kivy 將 RecycleView 翻了一番

Kivy 將 RecycleView 翻了一番

大話西游666 2021-12-29 19:44:56
有誰知道是什么導致了這種情況?我的 Kivy RecycleView 在可編輯的后面有一個奇怪的靜態版本 - 它不能以任何方式選擇或更改。這讓我覺得我可能有我所有 Kivy 小部件的重復版本?我很猶豫要不要粘貼我的所有代碼,因為它會訪問一個 api 并且在應用程序本身中包含憑據信息和許多個人信息。雙循環視圖class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,                                 RecycleBoxLayout):    ''' Adds selection and focus behaviour to the view. '''class SelectableLabel(RecycleDataViewBehavior, Label):    ''' Add selection support to the Label '''    index = None    selected = BooleanProperty(False)    selectable = BooleanProperty(True)    def refresh_view_attrs(self, rv, index, data):        ''' Catch and handle the view changes '''        self.index = index        return super(SelectableLabel, self).refresh_view_attrs(            rv, index, data)    def on_touch_down(self, touch):        ''' Add selection on touch down '''        if super(SelectableLabel, self).on_touch_down(touch):            return True        if self.collide_point(*touch.pos) and self.selectable:            return self.parent.select_with_touch(self.index, touch)    def apply_selection(self, rv, index, is_selected):        ''' Respond to the selection of items in the view. '''        self.selected = is_selected        if is_selected:            print("selection changed to {0}".format(rv.data[index]))        else:            print("selection removed for {0}".format(rv.data[index]))class RV(RecycleView):    def __init__(self, **kwargs):        super(RV, self).__init__(**kwargs)        self.data = [{'text': str(x)} for x in range(10)]class GuiApp(App):    theme_cls = ThemeManager()    theme_cls.theme_style = 'Dark'    previous_date = ''    previous_date2 = ''    StartDate = ObjectProperty("Start Date")    EndDate = ObjectProperty("End Date")    def build(self):        self.pickers = Factory.AnotherScreen()        presentation = Builder.load_file("gui.kv")        return presentation
查看完整描述

1 回答

?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

根本原因 - 看到雙打

雙倍是由于按文件名約定加載 kv 文件并使用Builder.


例如:使用Builder.load_file('gui.kv'),并且您的 kv 文件名是gui.kv.


片段

class GuiApp(App):

    ...


    def build(self):

        self.pickers = Factory.AnotherScreen()

        presentation = Builder.load_file("gui.kv")

        return presentation

解決方案

該問題有兩種解決方案。


方法一

將 App 類重命名GuiApp()為TestApp()


方法二

只要有根規則,例如BoxLayout:在 kv 文件中,就不需要在 App 類中返回任何內容。


刪除以下內容:


presentation = Builder.load_file("gui.kv")

return presentation

參考

KV語言 ? 如何加載KV


有兩種方法可以將 Kv 代碼加載到您的應用程序中:


按命名約定:


Kivy 查找與您的 App 類同名的小寫 Kv 文件,如果以“App”結尾,則減去“App”,例如:


MyApp -> my.kv

如果此文件定義了一個根小部件,它將附加到應用程序的根屬性并用作應用程序小部件樹的基礎。


按建造者約定:


您可以告訴 Kivy 直接加載字符串或文件。如果此字符串或文件定義了根小部件,它將由以下方法返回:


Builder.load_file('path/to/file.kv')

或者:


Builder.load_string(kv_string)

例子

主文件

from kivy.app import App



class GuiApp(App):


    def build(self):

        self.pickers = None



if __name__ == "__main__":

    GuiApp().run()

gui.kv

#:kivy 1.11.0


Button:

    text: 'Hello Kivy'

    font_size: 50

輸出

http://img1.sycdn.imooc.com//61cc4b8b00012ed407990625.jpg

查看完整回答
反對 回復 2021-12-29
  • 1 回答
  • 0 關注
  • 285 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號