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

  1. <legend id='9l1f2'><style id='9l1f2'><dir id='9l1f2'><q id='9l1f2'></q></dir></style></legend>

      <small id='9l1f2'></small><noframes id='9l1f2'>

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

    1. `with canvas:` (Python `with something() as x:`) 如何在 Ki

      how does `with canvas:` (Python `with something() as x:`) works implicitly in Kivy?(`with canvas:` (Python `with something() as x:`) 如何在 Kivy 中隱式工作?)

    2. <legend id='LLwel'><style id='LLwel'><dir id='LLwel'><q id='LLwel'></q></dir></style></legend>

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

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

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

                本文介紹了`with canvas:` (Python `with something() as x:`) 如何在 Kivy 中隱式工作?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我剛剛意識到在 Kivy 中使用 with Python 語句添加頂點指令的方式有些神秘(至少對我而言).例如,with 的使用方式是這樣的:

                I just realized there is something mysterious (at least for me) in the way you can add vertex instructions in Kivy with the with Python statement. For example, the way with is used goes something like this:

                ... some code
                class MyWidget(Widget)
                    ... some code 
                
                    def some_method (self):
                        with self.canvas:
                           Rectangle(pos=self.pos, size=self.size)
                

                一開始我以為只是我偶爾使用的with Python語句.但突然間我意識到事實并非如此.通常它看起來更像這樣(示例取自 這里):

                At the beginning I thought that it was just the with Python statement that I have used occasionally. But suddenly I realize it is not. Usually it looks more like this (example taken from here):

                with open('output.txt', 'w') as f:
                   f.write('Hi there!')
                

                在實例之后通常有一個 as 以及對象的類似和別名.在 Kivy 示例中,我們沒有定義和別名,這仍然可以.但令我困惑的部分是指令 Rectangle 仍然與 self.canvas 相關聯.在閱讀了 with 語句之后,我非常確信 Kivy 代碼應該寫成這樣:

                There is usually an as after the instance and something like and alias to the object. In the Kivy example we don't define and alias which is still ok. But the part that puzzles me is that instruction Rectangle is still associated to the self.canvas. After reading about the with statement, I am quite convinced that the Kivy code should be written like:

                class MyWidget(Widget)
                    ... some code 
                
                    def some_method (self):
                        with self.canvas as c:
                           c.add (Rectangle(pos=self.pos, size=self.size))
                

                我假設在內部方法 add 是被調用的方法.假設基于我們可以簡單地使用 self.add (Rectangle(pos=self.pos, size=self.size))

                I am assuming that internally the method add is the one being called. The assumption is based that we can simply add the rectangles with self.add (Rectangle(pos=self.pos, size=self.size))

                我是否遺漏了關于 with Python 語句的某些內容?或者這是 Kivy 實現的某種東西?

                Am I missing something about the with Python statement? or is this somehow something Kivy implements?

                推薦答案

                我不知道 Kivy,但我想我可以猜到這個具體的構造是如何工作的.

                I don't know Kivy, but I think I can guess how this specific construction work.

                with 語句不是保留與您正在交互的對象(畫布?)的句柄,而是將其存儲在對您隱藏的某個全局變量中.然后,您在 with 中使用的語句使用該全局變量來檢索對象.在塊的末尾,全局變量作為清理的一部分被清除.

                Instead of keeping a handle to the object you are interacting with (the canvas?), the with statement is programmed to store it in some global variable, hidden to you. Then, the statements you use inside with use that global variable to retrieve the object. At the end of the block, the global variable is cleared as part of cleanup.

                結果是一種權衡:代碼不那么明確(這通常是 Python 中需要的特性).但是,代碼更短,這可能更容易理解(假設讀者知道 Kivy 的工作原理).這實際上是在 Python 中制作嵌入式 DSL 的技術之一.

                The result is a trade-off: code is less explicit (which is usually a desired feature in Python). However, the code is shorter, which might lead to easier understanding (with the assumption that the reader knows how Kivy works). This is actually one of the techniques of making embedded DSLs in Python.

                涉及一些技術細節.例如,如果您希望能夠嵌套這樣的結構(將一個 with 放在另一個中),而不是一個簡單的全局變量,您可能希望使用一個全局變量來保存這些對象的堆棧.此外,如果您需要處理線程,您將使用線程局部變量而不是全局變量.但是通用機制仍然是相同的——Kivy 使用了一些保存在你無法直接控制的地方的狀態.

                There are some technicalities involved. For example, if you want to be able to nest such constructions (put one with inside another), instead of a simple global variable you would want to use a global variable that keeps a stack of such objects. Also, if you need to deal with threading, you would use a thread-local variable instead of a global one. But the generic mechanism is still the same—Kivy uses some state which is kept in a place outside your direct control.

                這篇關于`with canvas:` (Python `with something() as x:`) 如何在 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 - 自動更改角色顏色)
                <tfoot id='pfJVc'></tfoot>

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

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

                          主站蜘蛛池模板: 国产精品一区久久久 | 国产精品毛片久久久久久 | av喷水| 成人美女免费网站视频 | 免费视频一区二区三区在线观看 | 超黄毛片 | 国产精品免费一区二区三区四区 | 拍真实国产伦偷精品 | 国产剧情久久 | 欧美日韩高清免费 | av中文在线观看 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 日日干日日色 | 91性高湖久久久久久久久_久久99 | 激情av免费看 | 国产精品久久久久aaaa九色 | 成人在线视频网 | 久草中文在线 | 色影视| 99精品欧美一区二区蜜桃免费 | 久久综合久久自在自线精品自 | 亚洲精品视频播放 | 欧美精品在欧美一区二区少妇 | 久久久国产一区二区三区 | www.99re| 国产一区二区影院 | 一级大片网站 | 国产精品一区久久久 | 久久精品国产99国产精品 | 日韩免费毛片视频 | 色www精品视频在线观看 | www.com久久久 | 一区二区三区亚洲精品国 | 成人在线观看免费视频 | 国产激情在线 | 日韩中文字幕在线观看 | 亚洲网在线 | 国产精品一区二区久久久久 | 99久久久久 | 亚洲视频中文字幕 | 日韩理论电影在线观看 |