I have been trying to create a file chooser popup from a button release for an app.
I have managed a FileChooser, and Popups separately, but can’t work out the two together, can anyone here help with a solution?
I am trying to implement the PopUp in Python instead of Kivy.lang as this is the experience I have with popups. I am unable to get the Kivy Doc example to work either.
The Code I have at the moment is below.
import kivy
from kivy.uix.filechooser import FileChooserListView
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.popup import Popup
import os
Builder.load_string(
"""
<MyWidget>:
Button
text: "open"
on_release: root.load()
""")
class MyWidget(BoxLayout):
def load(self):
load_popup = Popup(
title = "Select logo",
size_hint = (None, None),
size = (500, 500)
)
file_load= FileChooserListView(
on_selection = self.selected(file_load.selection) #selection not in My
)
content = file_load
load_popup.content = content
load_popup.open()
def open(self, path, filename):
with open(os.path.join(path, filename[0])) as f:
print(f)
def selected(self, filename):
print("selected: %s" % filename[0])
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()
KiefyTk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.