我创建了一个Image对象,我想设置它的大小,但我不能这样做。代码,我创建了一个光标对象,它是图像,然后我尝试设置它的大小,但我自己.size =(10,10)对它没有影响。为什么它不起作用?
#!/usr/bin/kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.core.window import Window
class Root(FloatLayout):
pass
class Cursor(Image):
def __init__(self, **kwargs):
super(Cursor, self).__init__(**kwargs)
self.source = 'crosshair.png'
self.size = (10,10)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self, input_type='text')
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self,**kwargs):
print "hi"
def _on_keyboard_down(self,keyboard, keycode, text, modifiers):
if keycode[1] == 'up': self.y += 10
elif keycode[1] == 'down': self.y -= 10
elif keycode[1] == 'left': self.x -= 10
elif keycode[1] == 'right': self.x += 10
class YardApp(App):
def build(self):
layout = Root()
cursor = Cursor()
layout.add_widget(cursor)
return layout
if __name__ == '__main__':
YardApp().run()
答案 0 :(得分:3)
它的父级是FloatLayout,它根据pos_hint和size_hint自动设置子级的大小和位置。要禁用此行为,请设置timestable = [[count, factor * count] for count in range(0, 13)]
,之后您的手动大小设置将生效。