Загрузка изобращения из файла
load_imagefile.py
— 1 KB
Содержимое файла
""" Using the asynchronous data loader How to do it… We need only a Python file and the URL in this recipe. To complete the recipe: 1. Import the usual kivy package. 2. Import the Image and Loader packages. 3. Import the Widget package. 4. Define the e2App class. 5. Define the _image_Loaded() method, which loads the image in the app. 6. Define the build() method. 7. In this method, load the image in a proxy image. 8. Define the image variable instanced as Image(). 9. Return the image variable to display the load image: """ import kivy kivy.require('1.9.0') from kivy.app import App from kivy.uix.image import Image from kivy.loader import Loader class e2App(App): def _image_loaded(self, proxyImage): if proxyImage.image.texture: self.image.texture = proxyImage.image.texture def build(self): proxyImage = Loader.image( 'img0.png') proxyImage.bind(on_load=self._image_loaded) self.image = Image() return self.image if __name__ == '__main__': e2App().run()