【发布时间】:2014-07-02 08:08:11
【问题描述】:
如何在我的密码中显示图像?
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
class MyApp(App):
def build(self):
return Image('b1.png')
MyApp().run()
【问题讨论】:
如何在我的密码中显示图像?
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
class MyApp(App):
def build(self):
return Image('b1.png')
MyApp().run()
【问题讨论】:
您可以检查Image documentation 以查看图像源由source 属性控制。因此,您应该能够只更改一行以使其工作:
return Image(source='b1.png')
【讨论】:
对我来说可以接受的结果太全面太简单了。
我有一个更好的方法来使用 .kv 文件:
Kivy.kv(文件)
<main_display>:
BoxLayout:
orientation: "vertical"
Image:
id: imageView
source: '<random_name>.jpg'
allow_stretch: True
....
Kivy.py(文件)
class main_display(BoxLayout):
def __init__(self, **kwargs):
super(main_display,self).__init__()
# Photo can be reference by running the photo function once:
Clock.schedule_once(self.photo)
def photo(self,dt):
# Replace the given image source value:
self.ids.imageView.source = 'kivy_test.jpg'
Clock.schedule_interval(self.photo, 0.06) 来添加一些照片循环(动态)。我已经尝试直接分配 来自 kivy.py(文件)的属性“源”,但断言失败 错误。
享受,如果您不清楚,请发表评论!
【讨论】: