This repository has been archived on 2023-05-15. You can view files and clone it, but cannot push or open issues or pull requests.
app_deutschlandticket_kivy_.../ch.l3d.deutschlandticket/main.py
L3D 0a7dc3d686
All checks were successful
Build / Build for Android (push) Successful in 33m13s
First version: Open Image dialogue
2023-05-12 17:53:33 +02:00

43 lines
1.1 KiB
Python

#/usr/bin/env python3
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.uix.filechooser import FileChooserIconView
class ImageChooser(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = 'vertical'
self.file_chooser = FileChooserIconView()
self.add_widget(self.file_chooser)
self.open_button = Button(text='Open Image')
self.open_button.bind(on_press=self.open_image)
self.add_widget(self.open_button)
def open_image(self, instance):
if self.file_chooser.selection:
# Show Image
self.image = Image()
self.add_widget(self.image)
# Load Image
image_path = self.file_chooser.selection[0]
self.image.source = image_path
# Hide other Elements
self.remove_widget(self.file_chooser)
self.remove_widget(self.open_button)
class DeutschlandTicket(App):
def build(self):
return ImageChooser()
if __name__ == '__main__':
app = DeutschlandTicket()
app.run()