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

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

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

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

      1. 將變量從 .py 傳遞到 .kv 文件

        Pass variables from .py to .kv file(將變量從 .py 傳遞到 .kv 文件)
      2. <i id='Fe4Zs'><tr id='Fe4Zs'><dt id='Fe4Zs'><q id='Fe4Zs'><span id='Fe4Zs'><b id='Fe4Zs'><form id='Fe4Zs'><ins id='Fe4Zs'></ins><ul id='Fe4Zs'></ul><sub id='Fe4Zs'></sub></form><legend id='Fe4Zs'></legend><bdo id='Fe4Zs'><pre id='Fe4Zs'><center id='Fe4Zs'></center></pre></bdo></b><th id='Fe4Zs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Fe4Zs'><tfoot id='Fe4Zs'></tfoot><dl id='Fe4Zs'><fieldset id='Fe4Zs'></fieldset></dl></div>
        <legend id='Fe4Zs'><style id='Fe4Zs'><dir id='Fe4Zs'><q id='Fe4Zs'></q></dir></style></legend>

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

          <tbody id='Fe4Zs'></tbody>
            <bdo id='Fe4Zs'></bdo><ul id='Fe4Zs'></ul>

                <tfoot id='Fe4Zs'></tfoot>

                  本文介紹了將變量從 .py 傳遞到 .kv 文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用從 python 文件到 .kv 文件的變量所以我搜索了類似的問題,發現了使用 Property 的方式并編碼如下:

                  I am trying to use variables from python file to .kv file so I searched similar questions and found out the way use Property and coded like this:

                  # in python file
                  class Test2App(App):
                      abcd = StringProperty('test')
                      def build(self):
                          return presentation
                  
                  # in kv file
                  <MyButton@Button>:
                      text: "contents (%s)"%(app.abcd)
                  
                      background_color: (255, 255, 255,1)`
                  

                  然后出現錯誤.

                   AttributeError: 'NoneType' object has no attribute 'bind'
                     File "/usr/local/lib/python2.7/dist-packages/kivy/lang/builder.py", line 249, in create_handler
                       return eval(value, idmap), bound_list
                     File "/root/Desktop/hi/t2.kv", line 61, in <module>
                       text: "contents (%s)"%(app.abcd)
                     File "/usr/local/lib/python2.7/dist-packages/kivy/lang/parser.py", line 75, in __getattribute__
                       object.__getattribute__(self, '_ensure_app')()
                     File "/usr/local/lib/python2.7/dist-packages/kivy/lang/parser.py", line 70, in _ensure_app
                       app.bind(on_stop=lambda instance:
                  
                     File "/usr/local/lib/python2.7/dist-packages/kivy/lang/builder.py", line 615, in _apply_rule
                       rctx['ids'])
                     File "/usr/local/lib/python2.7/dist-packages/kivy/lang/builder.py", line 254, in create_handler
                       cause=tb)
                  

                  t2.py

                  #-*- coding: utf-8 -*-
                  __version__ = "1.0"
                  
                  import kivy
                  import os
                  kivy.require('1.10.0')
                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.button import Button
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.gridlayout import GridLayout
                  from kivy.uix.image import Image
                  from kivy.uix.label import Label
                  from kivy.animation import Animation
                  from kivy.clock import Clock
                  from kivy.properties import StringProperty
                  #from kivy.config import Config #windows size fixed
                  #Config.set('graphics', 'resizable', 0)
                  from kivy.core.window import Window 
                  Window.size = (540, 960)
                  #Window.size = (1080, 1920) 
                  ##########FOR BUS INFORMATION UPDATE#############
                  from urllib import urlencode, quote_plus
                  from urllib2 import Request as RQ
                  from urllib2 import urlopen as UO
                  import urllib
                  import xml.etree.ElementTree as etree
                  import os
                  import datetime
                  
                  
                  def oopath(ndid, uor):
                      path = os.path.join(ndid + '.txt')
                      return path
                  
                  ##############################################################################################################
                  
                  class StationTest(Screen):
                  
                      def __init__(self, **kwargs):
                          super(StationTest, self).__init__(**kwargs)
                  
                      oo = oopath('TESTTEST', 0) 
                      self.rpandgv(oo)
                  
                      def rpandgv(self,path): 
                      with open(path) as businfo:
                          Businfo= [] 
                          nolinenum=businfo.readline()
                          while nolinenum!='': 
                          Businfo.append(nolinenum)
                          leftstations = (businfo.readline().rstrip('
                  ') + ' stations'.rstrip('
                  '))
                          lefttime = (businfo.readline().rstrip('
                  ') + ' seconds'.rstrip('
                  '))
                          nolinenum = businfo.readline().rstrip('
                  ')
                          Businfo.append(leftstations)
                          Businfo.append(lefttime)
                          self.businfolist = Businfo
                          self.lenbil = int(len(Businfo))
                          self.numberoflist = int(len(Businfo)/3)
                  
                  
                  
                  
                  class ScreenManagement(ScreenManager):
                      pass
                  
                  presentation = Builder.load_file("t2.kv")
                  
                  class Test2App(App):
                      abcd = StringProperty('test')
                      def build(self):
                          return presentation
                  
                  
                  Test2App().run()
                  

                  t2.kv

                  # -*- coding: utf-8 -*-
                  #:import NoTransition kivy.uix.screenmanager.NoTransition
                  #:import SlideTransition kivy.uix.screenmanager.SlideTransition
                  #:import Label kivy.uix.button.Label
                  
                  ScreenManagement:
                      transition: SlideTransition(direction='left')
                      StationTest:
                  
                  <StationTest>: 
                      name: 'StationTest'
                      canvas:
                          Rectangle:
                              pos: self.pos
                              size: self.size 
                              source: 'image/background.png' #backgroundimage
                      header: _header
                      ScrollView:
                          FloatLayout:
                              size_hint_y: None
                              height: 500
                              BoxLayout:
                                  id: _header
                                  orientation: 'vertical'
                                  size_hint: 1, 0.10
                                  pos_hint: {'top': 1.0}
                                  anchor: _anchor
                                  canvas:
                                      Color:              
                                          rgba: 0.8, 0.6, 0.4, 1.0
                                      Rectangle:
                                          pos: self.pos
                                          size: self.size
                                  Label:
                                      text: "STATION > STATION"
                                      font_size: 40
                                  BoxLayout
                                      id: _anchor
                                      size_hint_y: 0.3
                                      canvas.before:
                                          Color:              
                                              rgba: 0.3, 0.5, 0.8, 1.0
                                          Rectangle:
                                              pos: self.pos
                                              size: self.size
                                      Label:
                                          text: "TEST1234"
                  
                              BoxLayout:
                                  orientation: 'vertical'
                                  size_hint: 1, 0.35
                                  padding: 0, -200, 0, 0
                                  MyButton:
                                  MyButton:
                                  MyButton:
                                  MyButton:
                  
                  
                  
                  <MyButton@Button>:
                      text: "contents (%s)"%(app.abcd)
                  
                      background_color: (255, 255, 255,1)
                  

                  推薦答案

                  這個問題有兩種解決方案.詳情請參考解決方案和示例.

                  There are two solutions to this problem. Please refer to the solutions and example for details.

                  變量abcd在解析kv文件時為None.添加if...else...語句解決問題.

                  The variable, abcd is None when the kv file is parsed. Add if...else... statement to solve the problem.

                  <MyButton@Button>:
                      text: "" if app.abcd is None else "contents (%s)"%(app.abcd)
                  
                      background_color: (255, 255, 255,1)    # white background color
                      color: 0, 0, 0, 1    # black color text
                  

                  解決方案 2:Python 代碼 - 在 build() 方法中初始化

                  build()方法中初始化變量,abcd.

                  class TestApp(App):
                      abcd = StringProperty('')
                  
                      def build(self):
                          self.abcd = 'test'
                          return ScreenManagement()
                  

                  示例

                  main.py

                  from kivy.app import App
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  from kivy.properties import StringProperty
                  
                  
                  class StationTest(Screen):
                      pass
                  
                  
                  class ScreenManagement(ScreenManager):
                      pass
                  
                  
                  class TestApp(App):
                      abcd = StringProperty('test')
                  
                      def build(self):
                          return ScreenManagement()
                  
                  
                  TestApp().run()
                  

                  test.kv

                  #:kivy 1.11.0
                  #:import SlideTransition kivy.uix.screenmanager.SlideTransition
                  
                  <ScreenManagement>:
                      transition: SlideTransition(direction='left')
                      StationTest:
                  
                  <StationTest>:
                      name: 'StationTest'
                      BoxLayout:
                          orientation: 'vertical'
                          size_hint: 1, 0.35
                          padding: 0, -200, 0, 0
                          MyButton:
                          MyButton:
                          MyButton:
                          MyButton:
                  
                  
                  
                  <MyButton@Button>:
                      # text: "" if app.abcd is None else "contents (%s)"%(app.abcd)
                      text: "contents (%s)"%(app.abcd)
                  
                      background_color: (1, 1, 1, 1)    # white background
                      color: 0, 0, 0, 1    # black color text
                  

                  輸出

                  這篇關于將變量從 .py 傳遞到 .kv 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)

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

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

                              <tbody id='tz66p'></tbody>

                            主站蜘蛛池模板: 亚洲成av | 亚洲成人精品一区 | 精品99在线 | 午夜av成人| 国产一级电影在线观看 | 久草成人网 | 午夜影院视频 | 第四色播日韩第一页 | 久久久久久91香蕉国产 | 亚洲成人精品国产 | 伊人二区| 日韩av在线免费 | 亚洲色图50p| 99视频在线免费观看 | 成人亚洲视频 | 亚洲网视频 | 成人h片在线观看 | 国产一区二区在线播放 | 91社影院在线观看 | 亚洲成人av一区二区 | 亚洲精品日韩在线 | 操视频网站 | 午夜影院免费体验区 | 国产二区视频 | 成人av在线网站 | 国产一级特黄视频 | 黄色免费在线观看网址 | 一级大黄| 国产成人高清视频 | 99久久精品国产一区二区三区 | 亚洲综合大片69999 | h视频在线播放 | 欧美日韩亚洲国产 | 天天综合永久 | 麻豆国产一区二区三区四区 | 一级片在线免费看 | 日韩福利 | 亚洲精品久久嫩草网站秘色 | 天天天操 | 毛片一级片 | 蜜桃视频在线观看免费视频网站www |