久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='95Dvz'></tfoot>
    <i id='95Dvz'><tr id='95Dvz'><dt id='95Dvz'><q id='95Dvz'><span id='95Dvz'><b id='95Dvz'><form id='95Dvz'><ins id='95Dvz'></ins><ul id='95Dvz'></ul><sub id='95Dvz'></sub></form><legend id='95Dvz'></legend><bdo id='95Dvz'><pre id='95Dvz'><center id='95Dvz'></center></pre></bdo></b><th id='95Dvz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='95Dvz'><tfoot id='95Dvz'></tfoot><dl id='95Dvz'><fieldset id='95Dvz'></fieldset></dl></div>
      <bdo id='95Dvz'></bdo><ul id='95Dvz'></ul>

      <legend id='95Dvz'><style id='95Dvz'><dir id='95Dvz'><q id='95Dvz'></q></dir></style></legend>

    1. <small id='95Dvz'></small><noframes id='95Dvz'>

      kivy 使用附加類來存儲來自多個屏幕的數據

      kivy using addtional class to store data from multiple screens(kivy 使用附加類來存儲來自多個屏幕的數據)

      <legend id='NW5Ni'><style id='NW5Ni'><dir id='NW5Ni'><q id='NW5Ni'></q></dir></style></legend>
        • <bdo id='NW5Ni'></bdo><ul id='NW5Ni'></ul>

          1. <i id='NW5Ni'><tr id='NW5Ni'><dt id='NW5Ni'><q id='NW5Ni'><span id='NW5Ni'><b id='NW5Ni'><form id='NW5Ni'><ins id='NW5Ni'></ins><ul id='NW5Ni'></ul><sub id='NW5Ni'></sub></form><legend id='NW5Ni'></legend><bdo id='NW5Ni'><pre id='NW5Ni'><center id='NW5Ni'></center></pre></bdo></b><th id='NW5Ni'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NW5Ni'><tfoot id='NW5Ni'></tfoot><dl id='NW5Ni'><fieldset id='NW5Ni'></fieldset></dl></div>
          2. <tfoot id='NW5Ni'></tfoot>

                  <tbody id='NW5Ni'></tbody>

                <small id='NW5Ni'></small><noframes id='NW5Ni'>

                本文介紹了kivy 使用附加類來存儲來自多個屏幕的數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我想向我的 kivy 應用程序添加一個額外的類,它只是一個信息存儲庫.我不確定在哪里執行此操作,或者是否建議使用這種方法.

                I want to add an additional class to my kivy app that is just an info storage depot. I'm not sure where to do this or if this approach is even advised.

                該應用有多個屏幕.每個屏幕都允許用戶進行選擇.用戶的選擇就是我想要存儲在附加類中的內容.附加類將存儲數據,然后最終使用 MQTT 將數據發送出去.另外,我想將類定義保存在一個單獨的文件中,這樣我就可以將程序組織成邏輯有序的塊.

                The app has multiple screens. Each screen allows the user to make a selection. The user's selection is what I want to store in the additional class. The additional class will store data then ultimately use MQTT to send the data out. Also, I wanted to keep the class definition in a separate file so I could organize the program into logically ordered chunks.

                (請記住,我只分享了一小部分代碼,但這應該足以表達我的問題)

                (keep in mind I'm sharing a small fraction of the code, but this should be representative enough to convey my question)

                我的 kivy python 代碼:

                My kivy python code:

                from kivy.app import App
                from kivy.uix.floatlayout import FloatLayout
                from kivy.uix.screenmanager import ScreenManager, Screen
                from storage import Storage  # <<========================== this is the addtional class
                
                # Screen Manager
                class MyScreenManager(ScreenManager):
                    pass
                
                
                # Background Color
                class BG(FloatLayout):
                    pass
                
                
                class VendorScreen(Screen):
                    pass
                
                
                class InvoiceScreen(Screen):
                    def __init__(self, **kwargs):
                        super(InvoiceScreen, self).__init__(**kwargs)
                        self.invoice = ''
                
                    def keyEntry(self, number):  # ............ Digit Pressed
                        invoice = self.ids.invoice  # ......... link to kivy Label
                        invoice.text += number  # ............. append number to invoice
                
                    def keyBack(self):  # ..................... Backspace
                        invoice = self.ids.invoice  # ......... link to kivy Label
                        invoice.text = invoice.text[:-1]  # ... remove last digit
                
                    def set_invoice(self):
                        invoice = self.ids.invoice
                        self.invoice = invoice.text
                
                
                class MainControlScreen(Screen):
                    pass
                
                
                # Main-Execution
                class mySuperApp(App):
                    def build(self):
                        return MyScreenManager()
                
                
                if __name__ == '__main__':
                    mySuperApp().run()
                

                我的kv碼:

                #:kivy 1.0.9
                
                <MyScreenManager>:
                    VendorScreen:  # ........ Incoming Delivery, Screen 2b
                        name: 'vendor_screen'
                    InvoiceScreen: # ........ .................. Screen 3b
                        name: 'invoice_screen'
                    MainControlScreen:  # ... .................. Screen 4b
                        name: 'main_control_screen'
                
                <BG>
                    AsyncImage:
                        source: 'img/screen1_background4.png'
                        size_hint: 1, 1
                
                <VendorScreen>
                    BG:
                    FloatLayout:
                        Button:
                            text: 'name1'
                            color: 1.0, 0.6, 0.0, 1
                            font_size: 40
                            size_hint_x: 0.45
                            size_hint_y: 0.35
                            pos_hint: {'x': 0.03, 'y': 0.50}
                            on_release:
                                root.manager.transition.direction = 'left'
                                root.manager.current = 'invoice_screen'
                        Button:
                            text: 'name2'
                            color: 1.0, 0.6, 0.0, 1
                            font_size: 40
                            size_hint_x: 0.45
                            size_hint_y: 0.35
                            pos_hint: {'x': 0.52, 'y': 0.50}
                            on_release:
                                root.manager.transition.direction = 'left'
                                root.manager.current = 'invoice_screen'
                        Button:
                            text: 'name3'
                            color: 1.0, 0.6, 0.0, 1
                            font_size: 40
                            size_hint_x: 0.45
                            size_hint_y: 0.35
                            pos_hint: {'x': 0.03, 'y': 0.10}
                            on_release:
                                root.manager.transition.direction = 'left'
                                root.manager.current = 'invoice_screen'
                        Button:
                            text: 'name4'
                            color: 1.0, 0.6, 0.0, 1
                            font_size: 40
                            size_hint_x: 0.45
                            size_hint_y: 0.35
                            pos_hint: {'x': 0.52, 'y': 0.10}
                            on_release:
                                root.manager.transition.direction = 'left'
                                root.manager.current = 'invoice_screen'
                
                <InvoiceScreen>
                    BG:
                        canvas:
                            Color:
                                rgba: 0.90, 0.90, 0.90, 0.5
                            Rectangle:
                                pos: (40, 295)
                                size: (320, 35)
                            Color:
                                rgba: 0, 0, 0, 1
                            Line:
                                points: 40, 295, 360, 295, 360, 330, 40, 330, 40, 295
                                width: 1
                    BoxLayout:
                        orientation: 'horizontal'  # break it up into left / right
                        FloatLayout:
                            Label:
                                pos_hint: {'x':0, 'y':.25}
                                font_size: 30
                                text: 'Enter Invoice Number'
                                color: 0.1, 0.1, 1, 1
                            Label:
                                id: invoice
                                pos_hint: {'x':0, 'y':.15}
                                font_size: 30
                                text: ''  # initially blank
                                color: 0, 0, 0, 1
                        GridLayout:
                            cols: 3  # number of columns
                            rows: 4  # number of rows
                            Button:
                                text: '1'
                                on_release: root.keyEntry('1')
                            Button:
                                text: '2'
                                on_release: root.keyEntry('2')
                            Button:
                                text: '3'
                                on_release: root.keyEntry('3')
                            Button:
                                text: '4'
                                on_release: root.keyEntry('4')
                            Button:
                                text: '5'
                                on_release: root.keyEntry('5')
                            Button:
                                text: '6'
                                on_release: root.keyEntry('6')
                            Button:
                                text: '7'
                                on_release: root.keyEntry('7')
                            Button:
                                text: '8'
                                on_release: root.keyEntry('8')
                            Button:
                                text: '9'
                                on_release: root.keyEntry('9')
                            Button:
                                text: '< DEL'
                                on_release: root.keyBack()
                            Button:
                                text: '0'
                                on_release: root.keyEntry('0')
                            Button:
                                text: 'Done'
                                on_release:
                                    root.set_invoice()
                                    root.manager.transition.direction = 'left'
                                    root.manager.current = 'main_control_screen'
                
                <MainControlScreen>
                    BG:
                        canvas:
                            Color:
                                rgba: 0, 0, 1, 1
                            Line:
                                points: 500, 180, 770, 180, 770, 450, 500, 450, 500, 180
                                width: 3
                    FloatLayout:
                        Label:  # foreground
                            pos_hint: {'x': 0.30, 'y': 0.13}
                            font_size: 80
                            text: '5'
                            color: 1.0, 0.6, 0.0, 1
                        Button:
                            size_hint_x: 0.2
                            size_hint_y: 0.1
                            pos_hint: {'x': 0.05, 'y': 0.05}
                            text: 'Auto-Reject'
                            on_release:
                                root.manager.transition.direction = 'up'
                                root.manager.current = 'vendor_screen'
                        Button:
                            size_hint_x: 0.2
                            size_hint_y: 0.1
                            pos_hint: {'x': 0.75, 'y': 0.05}
                            text: 'Photo' 
                            on_release:
                                root.manager.transition.direction = 'left'
                                root.manager.current = 'invoice_screen'
                

                最后是我的額外課程:

                from datetime import datetime, date
                import calendar
                
                
                class Storage(object):
                    def __init__(self):
                        self.invoice = 0
                        self.unit_name = ''
                        self.unit_number = ''
                        self.receiver = ''
                        self.vendor = ''
                        self.day = calendar.day_name[date.today().weekday()]
                        self.delivery_time = datetime.now()  
                        self.package_condition = True
                        self.email = ''
                        self.location = ('32.0, -117.0',)
                        self.duration = 0  
                        self.img = 'img.jpg'
                

                所以我的問題是,我在哪里以及如何使用我的附加類存儲"?我希望所有 kivy 類都能夠訪問它的單個實例,但我不知道該怎么做.

                So my question is, where and how do I use my addtional class 'Storage'? I want all the kivy classes to be able to access a single instance of it, but I cannot figure out how to do that.

                我嘗試在 mySuperApp().run() 之前實例化一個類,但我無法在其他類中訪問它.我嘗試使用 global 來訪問該實例,但這不起作用.

                I tried instantiating a class just before mySuperApp().run() but I cannot access it inside the other classes. I tried using global to access the instance, but that didn't work.

                我考慮過從類繼承,但我不知道如何做到這一點......我從不同屏幕中的 Storage 繼承開始,但是,這不允許我訪問包含所有數據的單個實例是,我不得不從多個類中提取實例變量來收集完整的數據集.然后我嘗試在 Storage 中繼承 mySuperApp,然后從 Storage 中運行 ScreenManager,但這不起作用.它運行了,但我無法從其他類訪問實例變量.也許我需要在所有其他類中繼續從 Storage 繼承?

                I thought about inheriting from the class, but I'm not sure how to do this... I started by inheriting from Storage in my different screens, however, that does not let me access a single instance where all my data is, rather I would have to pull instance variables from multiple classes to amass the full data set. Then I tried inheriting mySuperApp in Storage, then running the ScreenManager from Storage, but that didn't work. It ran, but I couldn't access the instance variables from the other classes. Maybe I need to keep inheriting from Storage in all the other classes?

                我不確定如何處理這個問題,因為 kivy 部分只是程序的一小部分.最后,我將需要幾個額外的課程,但我不明白如何或在哪里鏈接這些課程.獲得概念后,我會將其應用于其他必要的課程,但我不知道從哪里開始.

                I'm not sure how to approach this as the kivy part is only a fraction of the program. In the end I will need several additional classes, but I don't understand how or where to link these. Once I get the concept I will apply it to the other necessary classes, but I don't know where to start.

                推薦答案

                您可以使用 ScreenManager 來共享數據.
                ScreenManager 將始終是所有屏幕的父級.因此,您可以通過以下三種方式訪問??管理器.

                You could use the ScreenManager to share data.
                The ScreenManager will allways be parent of all the screens. So here are three ways you can access the manager.

                root.manager:
                Screen 都有一個名為 manager 的屬性,也就是這個 Screen 所在的 ScreenManager.所以您可以從任何這樣的屏幕訪問它.

                root.manager:
                The Screen's all have an attribute called manager, which is the ScreenManager which this Screen is in. So you can access it from any screen like this.

                root.parent:
                如果 Widget 位于另一個小部件中,它們都將具有它的 parent.在這種情況下,Screen 的父級是 ScreenManager.因此,您可以從任何這樣的屏幕訪問它.

                root.parent:
                The Widget's if they are in another widget will all have it's parent. In this case, the Screen's parent is the ScreenManager. So you can access it from any screen like this.

                app.root:
                每個應用程序都有一個 root.在這種情況下,應用程序的根是 ScreenManager.所以你可以像這樣從任何地方訪問它.

                app.root:
                Every app has a root. In this case the root of the app, is the ScreenManager. So you can access it from anywhere like this.

                試試這個例子,用三個按鈕演示:

                Try this example, with three buttons demonstrating this:

                from kivy.app import App
                from kivy.uix.screenmanager import Screen, ScreenManager
                from kivy.lang import Builder
                from kivy.properties import StringProperty
                
                
                class MyScreenManager(ScreenManager):
                    shared_data = StringProperty("")
                
                
                class Screen1(Screen):
                    pass
                
                class Screen2(Screen):
                    pass
                
                
                root = Builder.load_string('''
                
                <Screen1>:
                    name: "screen1"
                    BoxLayout:
                        orientation: "vertical"
                        TextInput:
                            on_text:
                                root.manager.shared_data = self.text
                        Label:
                            text:
                                root.manager.shared_data
                        Button:
                            text: "Go to screen2"
                            on_release: root.manager.current = "screen2"
                
                        Button:
                            text: "root.manager.shared_data"
                            on_release:
                                print(root.manager.shared_data)
                        Button:
                            text: "root.parent.shared_data"
                            on_release:
                                print(root.parent.shared_data)
                        Button:
                            text: "app.root.shared_data"
                            on_release:
                                print(app.root.shared_data)
                
                
                
                <Screen2>:
                    name: "screen2"
                    BoxLayout:
                        orientation: "vertical"
                        TextInput:
                            on_text:
                                root.manager.shared_data = self.text
                        Label:
                            text:
                                root.manager.shared_data
                        Button:
                            text: "Go to screen1"
                            on_release: root.manager.current = "screen1"
                
                
                MyScreenManager:
                    Screen1:
                    Screen2:
                
                ''')
                
                
                
                class MyApp(App):
                    def build(self):
                        return root
                

                這篇關于kivy 使用附加類來存儲來自多個屏幕的數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <bdo id='LEDNW'></bdo><ul id='LEDNW'></ul>

                • <i id='LEDNW'><tr id='LEDNW'><dt id='LEDNW'><q id='LEDNW'><span id='LEDNW'><b id='LEDNW'><form id='LEDNW'><ins id='LEDNW'></ins><ul id='LEDNW'></ul><sub id='LEDNW'></sub></form><legend id='LEDNW'></legend><bdo id='LEDNW'><pre id='LEDNW'><center id='LEDNW'></center></pre></bdo></b><th id='LEDNW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LEDNW'><tfoot id='LEDNW'></tfoot><dl id='LEDNW'><fieldset id='LEDNW'></fieldset></dl></div>
                    1. <small id='LEDNW'></small><noframes id='LEDNW'>

                      <tfoot id='LEDNW'></tfoot>
                          <tbody id='LEDNW'></tbody>

                        1. <legend id='LEDNW'><style id='LEDNW'><dir id='LEDNW'><q id='LEDNW'></q></dir></style></legend>
                          主站蜘蛛池模板: 国产不卡一区在线观看 | 色爽女 | 成人久草 | 成人亚洲片 | 亚洲精品国产a久久久久久 午夜影院网站 | 黄色在线播放视频 | 欧美日韩在线播放 | 婷婷二区 | 午夜免费观看体验区 | 国产一区二区三区日韩 | 精品三级在线观看 | 欧美一区二区三区视频 | 国产精品永久免费 | 中文字幕一区二区三区不卡 | 一区二区在线免费观看 | 中文字幕亚洲视频 | 成人精品在线观看 | 色噜噜狠狠色综合中国 | 久久综合一区二区 | av入口 | 九九精品在线 | 黄色大全免费看 | 亚洲国产精品99久久久久久久久 | 成人福利网站 | 日韩欧美视频 | 91麻豆精品国产91久久久更新资源速度超快 | 欧洲性生活视频 | 日日骚视频 | 美国一级黄色片 | 日韩一区二区三区精品 | 最新中文字幕在线 | 日韩成人高清 | 欧美一级在线免费观看 | 国产精品美女久久久久久久网站 | 99精品一区二区三区 | 久久精品一区 | 欧洲性生活视频 | 国产成人综合亚洲欧美94在线 | 蜜月va乱码一区二区三区 | 欧美一二区| www..com18午夜观看 |