pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <bdo id='G5mZu'></bdo><ul id='G5mZu'></ul>

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

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

    1. <legend id='G5mZu'><style id='G5mZu'><dir id='G5mZu'><q id='G5mZu'></q></dir></style></legend>
    2. <tfoot id='G5mZu'></tfoot>

      Python+kivy+SQLite:如何設置標簽初始值以及如何更新

      Python+kivy+SQLite: How to set label initial value and how to update label text?(Python+kivy+SQLite:如何設置標簽初始值以及如何更新標簽文本?)

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

        <tfoot id='aniGJ'></tfoot>

          • <i id='aniGJ'><tr id='aniGJ'><dt id='aniGJ'><q id='aniGJ'><span id='aniGJ'><b id='aniGJ'><form id='aniGJ'><ins id='aniGJ'></ins><ul id='aniGJ'></ul><sub id='aniGJ'></sub></form><legend id='aniGJ'></legend><bdo id='aniGJ'><pre id='aniGJ'><center id='aniGJ'></center></pre></bdo></b><th id='aniGJ'></th></span></q></dt></tr></i><div class="4u4gwoi" id='aniGJ'><tfoot id='aniGJ'></tfoot><dl id='aniGJ'><fieldset id='aniGJ'></fieldset></dl></div>
              <tbody id='aniGJ'></tbody>
              <legend id='aniGJ'><style id='aniGJ'><dir id='aniGJ'><q id='aniGJ'></q></dir></style></legend>
                <bdo id='aniGJ'></bdo><ul id='aniGJ'></ul>

                本文介紹了Python+kivy+SQLite:如何設置標簽初始值以及如何更新標簽文本?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                大家,

                我想使用 kivy+Python 來顯示 db 文件中的項目.

                I want to use kivy+Python to display items from a db file.

                為此,我之前問過一個問題:Python+kivy+SQLite: How一起使用

                To this purpose I have asked a question before: Python+kivy+SQLite: How to use them together

                鏈接中的應用程序包含一個屏幕.它工作得很好.

                The App in the link contains one screen. It works very well.

                今天我已將應用程序更改為 兩個 屏幕.第一屏沒有特殊要求,只是將App引導到第二屏.在 second screen 中有一個 label 和一個 button.通過單擊 button 我想更改 label text.label text 指的是我在上面鏈接中的 db 文件中的 car type.

                Today I have changed the App to two screens. The first screen has no special requirement but to lead the App to the second screen. In the second screen there is a label and a button. By clicking the button I want to have the label text changed. The label text refers to the car type from the db file that I have in the link above.

                對于這兩個屏幕的設計,我有兩個問題:

                For this two screens design, I have two questions:

                問題一:點擊按鈕時如何更新label text?

                我嘗試了兩種方法:

                方法一: self.ids.label.text = str(text)
                它向我顯示了錯誤消息: AttributeError: 'super' object has no attribute '__getattr__' 我用谷歌搜索了很多,但仍然無法理解.

                Method A: self.ids.label.text = str(text)
                It shows me the error message: AttributeError: 'super' object has no attribute '__getattr__' I have googled a lot but still cannot understand.

                方法B: self.ids["label"].text = str(text)它向我顯示錯誤消息: KeyError: 'label' 我很困惑,因為我定義了 label.

                Method B: self.ids["label"].text = str(text) It shows me the error message: KeyError: 'label' I am confused because I have the label defined.

                問題2:如何將label origin text設置為一種車型,這樣每次第二屏顯示時,已經有車型顯示了.

                Question 2: How to set the label origin text to one of the car type, so that everytime the second screen is shown, there is already a car type shown.

                代碼如下:(db文件請參考上面的鏈接)

                Here is the code: (For the db file please refer to the link above.)

                # -*- coding: utf-8 -*-
                from kivy.app import App
                from kivy.base import runTouchApp
                from kivy.lang import Builder
                from kivy.properties import ListProperty
                from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
                from kivy.uix.boxlayout import BoxLayout
                from kivy.uix.gridlayout import GridLayout
                from kivy.uix.floatlayout import FloatLayout
                from kivy.uix.label import Label
                from kivy.uix.widget import Widget
                from kivy.graphics import Rectangle
                from kivy.properties import NumericProperty, StringProperty, BooleanProperty, ListProperty
                from kivy.base import runTouchApp
                from kivy.clock import mainthread
                
                import sqlite3
                import random
                
                class MyScreenManager(ScreenManager):
                
                    def init(self, **kwargs):
                        super().__init__(**kwargs)
                
                        @mainthread  # execute within next frame
                        def delayed():
                            self.load_random_car()
                        delayed()
                
                    def load_random_car(self):
                        conn = sqlite3.connect("C:\test.db")
                        cur = conn.cursor()
                
                        cur.execute("SELECT * FROM Cars ORDER BY RANDOM() LIMIT 1;")
                
                        currentAll = cur.fetchone()
                        conn.close()
                        currentAll = list(currentAll)   # Change it from tuple to list
                
                        print currentAll
                
                        current    = currentAll[1]
                        print current
                        self.ids.label.text = str(current)    # Method A
                #        self.ids["label"].text = str(current) # Method B 
                
                class FirstScreen(Screen):
                    pass
                
                class SecondScreen(Screen):
                    pass
                
                root_widget = Builder.load_string('''
                #:import FadeTransition kivy.uix.screenmanager.FadeTransition
                MyScreenManager:
                    transition: FadeTransition()
                    FirstScreen:
                    SecondScreen:
                
                <FirstScreen>:
                    name: 'first'
                    BoxLayout:
                        orientation: 'vertical'
                        Label:
                            text: "First Screen"
                            font_size: 30
                        Button:
                            text: 'Go to 2nd Screen'
                            font_size: 30
                            on_release:  app.root.current = 'second'
                
                <SecondScreen>:
                    name: 'second'
                    BoxLayout:
                        orientation: 'vertical'
                        Label:
                            id: label
                            text: 'click to get a new car'   # I want its text changed when the button is clicked everytime. And its original text value should be one of the random car type from the db file.
                            font_size: 30
                        Button:
                            text: 'Click to get a random car'
                            font_size: 30
                            on_release:  app.root.load_random_car()
                
                ''')
                
                class ScreenManager(App):
                    def build(self):
                        return root_widget
                
                if __name__ == '__main__':
                    ScreenManager().run()
                

                我從互聯網上閱讀了很多內容,但我無法全部理解.:-(

                I have read a lot from internet, but I cannot understand them all. :-(

                請幫助我更正代碼.非常感謝!

                Please help me to correct the code. Thank you so much!

                推薦答案

                from kivy.app import App
                from kivy.lang import Builder
                from kivy.properties import StringProperty
                from kivy.uix.widget import Widget
                
                Builder.load_string("""
                <ScreenX>
                    BoxLayout:
                        orientation: 'vertical'
                        Label:
                            text: root.label_text
                        Button:
                            text: 'Click Me'
                            on_release: root.on_clicked_button()
                """)
                
                class ScreenX(Widget):
                    label_text = StringProperty("Default Value")
                    def on_clicked_button(self):
                        self.label_text = "New Text!"
                
                
                class MyApp(App):
                    def build(self):
                        return ScreenX()
                
                MyApp().run()
                

                通常是你會這樣做的方式......

                is typically how you would do this ...

                這篇關于Python+kivy+SQLite:如何設置標簽初始值以及如何更新標簽文本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                Get current location during app launch(在應用啟動期間獲取當前位置)
                locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)

                  <tbody id='6OWha'></tbody>

                  <small id='6OWha'></small><noframes id='6OWha'>

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

                      <i id='6OWha'><tr id='6OWha'><dt id='6OWha'><q id='6OWha'><span id='6OWha'><b id='6OWha'><form id='6OWha'><ins id='6OWha'></ins><ul id='6OWha'></ul><sub id='6OWha'></sub></form><legend id='6OWha'></legend><bdo id='6OWha'><pre id='6OWha'><center id='6OWha'></center></pre></bdo></b><th id='6OWha'></th></span></q></dt></tr></i><div class="iuaekie" id='6OWha'><tfoot id='6OWha'></tfoot><dl id='6OWha'><fieldset id='6OWha'></fieldset></dl></div>

                        • <tfoot id='6OWha'></tfoot>
                          主站蜘蛛池模板: 温湿度记录纸_圆盘_横河记录纸|霍尼韦尔记录仪-广州汤米斯机电设备有限公司 | SPC工作站-连杆综合检具-表盘气动量仪-内孔缺陷检测仪-杭州朗多检测仪器有限公司 | 理化生实验室设备,吊装实验室设备,顶装实验室设备,实验室成套设备厂家,校园功能室设备,智慧书法教室方案 - 东莞市惠森教学设备有限公司 | 油液红外光谱仪-油液监测系统-燃油嗅探仪-上海冉超光电科技有限公司 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | 地图标注|微信高德百度地图标注|地图标记-做地图[ZuoMap.com] | 河南彩印编织袋,郑州饲料编织袋定制,肥料编织袋加工厂-盛军塑业 河南凯邦机械制造有限公司 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 顶空进样器-吹扫捕集仪-热脱附仪-二次热解吸仪-北京华盛谱信仪器 | 酒吧霸屏软件_酒吧霸屏系统,酒吧微上墙,夜场霸屏软件,酒吧点歌软件,酒吧互动游戏,酒吧大屏幕软件系统下载 | 政府回应:200块在义乌小巷能买到爱情吗?——揭秘打工族省钱约会的生存智慧 | 全国国际化学校_国际高中招生_一站式升学择校服务-国际学校网 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 水轮机密封网 | 水轮机密封产品研发生产厂家 | 新能源汽车教学设备厂家报价[汽车教学设备运营18年]-恒信教具 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 浙江自考_浙江自学考试网 | 阁楼货架_阁楼平台_仓库仓储设备_重型货架_广州金铁牛货架厂 | 304不锈钢无缝管_不锈钢管厂家 - 隆达钢业集团有限公司 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 上海三信|ph计|酸度计|电导率仪-艾科仪器 | 北京百度网站优化|北京网站建设公司-百谷网络科技 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 桁架机器人_桁架机械手_上下料机械手_数控车床机械手-苏州清智科技装备制造有限公司 | 2-羟基泽兰内酯-乙酰蒲公英萜醇-甘草查尔酮A-上海纯优生物科技有限公司 | 迪威娱乐|迪威娱乐客服|18183620002 | CE认证_产品欧盟ROHS-REACH检测机构-商通检测 | 明渠式紫外线杀菌器-紫外线消毒器厂家-定州市优威环保 | 北京西风东韵品牌与包装设计公司,创造视觉销售力! | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | 电动葫芦|环链电动葫芦-北京凌鹰名优起重葫芦 | 体坛网_体坛+_体坛周报新闻客户端 | 浙江浩盛阀门有限公司| 动力配电箱-不锈钢配电箱-高压开关柜-重庆宇轩机电设备有限公司 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 泡沫消防车_水罐消防车_湖北江南专用特种汽车有限公司 | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 臭氧灭菌箱-油桶加热箱-原料桶加热融化烘箱-南京腾阳干燥设备厂 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 | 上海道勤塑化有限公司 |