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

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

    <small id='8KKVr'></small><noframes id='8KKVr'>

      <tfoot id='8KKVr'></tfoot>

      • <bdo id='8KKVr'></bdo><ul id='8KKVr'></ul>

    1. 如何在運(yùn)行時(shí)更改 Kivy 中小部件的顏色?

      How do I change the color of my widget in Kivy at run time?(如何在運(yùn)行時(shí)更改 Kivy 中小部件的顏色?)

          • <small id='iBVEv'></small><noframes id='iBVEv'>

            <tfoot id='iBVEv'></tfoot>

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

                本文介紹了如何在運(yùn)行時(shí)更改 Kivy 中小部件的顏色?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我無法在 Kivy 中更改簡(jiǎn)單小部件的顏色.我可以在創(chuàng)建小部件時(shí)設(shè)置顏色,但之后無法更改.

                I'm having trouble changing the color of a simple widget in Kivy. I can set the color when I create the widget, but I can't change it afterwards.

                這里是簡(jiǎn)單的布局定義文件circletest.kv.它定義了一個(gè)圓圈,其中顏色(實(shí)際上只是 r,來自 rgba)、位置和大小都鏈接到小部件類中的變量.

                Here is the simple layout definition file circletest.kv. It defines a circle where the color (actually just the r, from rgba), position and size are all linked to variables in the widget class.

                #:kivy 1.4.1
                
                <CircleWidget>:
                    canvas:
                        Color:
                            rgba: self.r,1,1,1
                        Ellipse:
                            pos: self.pos
                            size: self.size
                

                這是應(yīng)用程序 circletest.py.它創(chuàng)建并顯示簡(jiǎn)單的小部件.創(chuàng)建對(duì)象時(shí)成功設(shè)置顏色和位置.單擊小部件時(shí),小部件可以更改它自己的位置,但是當(dāng)我嘗試更改顏色時(shí),什么也沒有發(fā)生.

                Here's the application circletest.py. It creates and displays the simple widget. The color and position are successfully set when the object is created. When the widget is clicked the widget can change it's own position, but when I try to change the color nothing happens.

                import kivy
                kivy.require('1.4.1')
                from kivy.app import App
                from kivy.lang import Builder
                from kivy.uix.widget import Widget
                
                Builder.load_file('circletest.kv')
                
                class CircleWidget(Widget):
                
                    def __init__(s, **kwargs):
                        s.size= [50,50]
                        s.pos = [100,50]
                        s.r = 0
                        super(CircleWidget, s).__init__(**kwargs)
                
                    def on_touch_down(s, touch):
                        if s.collide_point(touch.x,touch.y):    
                            s.pos = [s.pos[1],s.pos[0]]           # This works
                            s.r = 1.0                       # <---- This does nothing!
                
                class TestApp(App):
                
                    def build(s):
                        parent = Widget()
                        w = CircleWidget()
                        parent.add_widget(w)
                        return parent
                
                if __name__ == '__main__':
                    TestApp().run()
                

                誰(shuí)能看出問題所在?

                更新

                仍然不確定這個(gè)問題的答案是什么,但我確實(shí)有一個(gè)解決方法:

                Still not sure what the answer to this question is, but I do have a work around:

                在 .kv 文件中,我將顏色指向?qū)ο笾械囊粋€(gè)變量.用于提取初始顏色:

                In the .kv file I pointed the color to a variable in my object. Works for extracting the initial color:

                Color:
                    rgba: self.col
                

                當(dāng)我想從 .py 文件中更改顏色時(shí),我會(huì)遍歷畫布中的所有指令并修改顏色"類型的第一個(gè)指令.顯然這是一種 hack,并且不適用于具有多個(gè) Color: 屬性的小部件:

                When I want to change the color from the .py file I loop through all the instructions in the canvas and modify the first one of type "Color". Obviously this is a hack, and won't work on widgets with more than one Color: property:

                for i in s.canvas.get_group(None):
                    if type(i) is Color:
                        i.r, i.g, i.b, i.a = v
                        break
                

                我將所有內(nèi)容封裝在一個(gè)屬性中,這樣使用起來很整潔:

                I wrapped that all up in a property so it's neat to use:

                class CircleWidget(Widget):
                
                    def get_col(s):
                        return s._col
                
                    def set_col(s,v):
                        for i in s.canvas.get_group(None):
                            if type(i) is Color:
                                i.r, i.g, i.b, i.a = v
                                break
                        s._col = v
                
                    col = property(get_col, set_col)
                
                    def __init__(s, **kwargs):
                        s.size= [50,50]
                        s.pos = [100,50]
                        s._col = (1,1,0,1)
                        super(CircleWidget, s).__init__(**kwargs)
                
                    def on_touch_down(s, touch):
                        if s.collide_point(touch.x,touch.y):    
                            s.col = (s.col[::-1]) # Set to some other color
                

                目前似乎可以使用.如果您知道更好的方法,請(qǐng)告訴我.我確信一定有一個(gè)更簡(jiǎn)單的方法,而且我遺漏了一些明顯的東西!

                Seems to work for now. Please let me know if you know a better way of doing this. I'm sure there must be a simpler way, and that I'm missing something obvious!

                推薦答案

                在您的初始版本中,您只是缺少屬性聲明

                In your initial version, you were just missing the declaration of the property

                from kivy.properties import NumericProperty
                

                在標(biāo)題和

                r = NumericProperty(0)
                

                就在class CircleWidget(Widget)下:

                另外,您聲明您的 kv 文件名為 circletest.kv,但您的應(yīng)用程序名為 TestApp,因此您應(yīng)該更改其中一個(gè)以使其連貫,否則將找不到您的 kv 文件,但您不這樣做'不要報(bào)告任何問題,我想這只是問題中的錯(cuò)字.剛剛看到 Builder.load_file ok,

                also, you state that your kv file is named circletest.kv, but your app is named TestApp, so you should change one of them to make them coherent, or your kv file won't be found, but as you don't report any issue with that, i guess it's only a typo in the question. edit: just saw the Builder.load_file ok,

                干杯.

                這篇關(guān)于如何在運(yùn)行時(shí)更改 Kivy 中小部件的顏色?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

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

                  <tbody id='bH9yp'></tbody>

              • <tfoot id='bH9yp'></tfoot>
                <legend id='bH9yp'><style id='bH9yp'><dir id='bH9yp'><q id='bH9yp'></q></dir></style></legend>

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

                        <i id='bH9yp'><tr id='bH9yp'><dt id='bH9yp'><q id='bH9yp'><span id='bH9yp'><b id='bH9yp'><form id='bH9yp'><ins id='bH9yp'></ins><ul id='bH9yp'></ul><sub id='bH9yp'></sub></form><legend id='bH9yp'></legend><bdo id='bH9yp'><pre id='bH9yp'><center id='bH9yp'></center></pre></bdo></b><th id='bH9yp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bH9yp'><tfoot id='bH9yp'></tfoot><dl id='bH9yp'><fieldset id='bH9yp'></fieldset></dl></div>
                        1. 主站蜘蛛池模板: 色综合激情 | 中文字幕动漫成人 | 91原创视频在线观看 | 国产精品乱码一区二三区小蝌蚪 | 一级黄色裸片 | 一区二区高清在线观看 | 成人在线免费观看视频 | 在线欧美激情 | 国产二区三区 | 国产精品嫩草影院精东 | 亚洲视频自拍 | 欧产日产国产精品视频 | 久久久不卡网国产精品一区 | av片免费 | 狠狠的干| 日本免费在线观看视频 | 91大神新作在线观看 | 91大神xh98xh系列全部 | 99精品国产一区二区三区 | 精品无码久久久久久国产 | 亚洲免费在线视频 | 少妇精品亚洲一区二区成人 | 欧美a级成人淫片免费看 | 色婷婷综合久久久中字幕精品久久 | 91在线免费视频 | 日韩视频区 | av黄色在线 | 日本精品一区二区三区视频 | 久草青青草 | 国产伦一区二区三区四区 | 日日操操| 国产亚洲精品精品国产亚洲综合 | 国产一级视频在线播放 | 国产一区二区三区免费观看视频 | 久久久精品综合 | 伊人网在线看 | 日本一区二区三区免费观看 | 国产激情| 久久九精品 | 国产激情视频网站 | 国产精品久久久久久久久久久久久 |