[英]why size of kivy ` s widget isn`t real?
有我的代碼:
class MyGame(Widget):
def prepare_game(self):
print(self.height, self.width)
class MyApp(App):
def build(self):
game = MyGame()
game.prepare_game()
return game
MyApp().run()
輸出是 100 100,但事實並非如此。 當我想調用一次方法 prepare_game() 時,我可以找出小部件的實際大小嗎?
這是因為在上面的示例中,未設置小部件的大小。 在這種情況下,您將獲得默認大小,即 100, 100。更新后的大小始終可以通過on_size
方法找到,如下例所示。
from kivy.app import App
from kivy.uix.widget import Widget
class MyGame(Widget):
def prepare_game(self):
print(self.height, self.width)
def on_size(self, *args):
print(self.size)
class MyApp(App):
def build(self):
game = MyGame()
game.prepare_game()
return game
MyApp().run()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.