Kivy Filechooser how to select a directory

Asked

Viewed 183 times

0

I need to create an interface where the user can select a directory, my code:

class MainScreen(FloatLayout):
    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)

        b1 = Button(text='iniciar',
        pos_hint={'x':.375, 'y':.65}, size_hint=(.25, .05))
        t1 = TextInput(pos_hint={'x':.375, 'y':.55}, size_hint=(.25, .05))
        t2 = TextInput(pos_hint={'x':.375, 'y':.45}, size_hint=(.25, .05))
        t3 = TextInput(pos_hint={'x':.375, 'y':.35}, size_hint=(.25, .05))
        l1 = Label(text='Entrada:', pos_hint={'x':.375, 'y':.60}, size_hint=(.25, .05))
        l2 = Label(text='Saida:', pos_hint={'x':.375, 'y':.50}, size_hint=(.25, .05))
        l3 = Label(text='Objeto:',pos_hint={'x':.375, 'y':.40}, size_hint=(.25, .05))
        i1 = Image(source='logoheader.png', pos_hint={'x':.600, 'y':.10}, size_hint=(.35, .1))
        b2 = Button(text='Select',
        pos_hint={'x':.640, 'y':.55}, size_hint=(.05, .05))
        b2.bind(on_press = self.fc)
        b3 = Button(text='Select',
        pos_hint={'x':.640, 'y':.45}, size_hint=(.05, .05))
        b4 = Button(text='Select',
        pos_hint={'x':.640, 'y':.35}, size_hint=(.05, .05))

        self.add_widget(b1)
        self.add_widget(t1)
        self.add_widget(t2)
        self.add_widget(t3)
        self.add_widget(l1)
        self.add_widget(l2)
        self.add_widget(l3)
        self.add_widget(i1)
        self.add_widget(b2)
        self.add_widget(b3)
        self.add_widget(b4)


    def fc(self, button):
        floatlayout = FloatLayout()
        b1 = Button(text='Selecionar', size_hint=(.5, .1), pos_hint={'x':.0, 'y':.005})
        b2 = Button(text='Cancelar', size_hint=(.5, .1), pos_hint={'x':.5, 'y':.005})
        fc1 = FileChooserIconView(size_hint=(1, .9), pos_hint={'x':0, 'y':.12})

        floatlayout.add_widget(b1)
        floatlayout.add_widget(b2)
        floatlayout.add_widget(fc1)

        popup = Popup(content=(floatlayout))
        popup.open()



class MainApp(App):
    def build(self):
        return MainScreen()

MainApp().run()

The problem is that the kivy automatically opens the folders whenever you click them, different from windows for example where the first click selects the file and the second enters the directory, how could I change it ? Because I have a select button that is ready to receive a function once the user has selected a folder.

This is my interface window at the moment:

inserir a descrição da imagem aqui

And here what happens after a single click on some folder:

inserir a descrição da imagem aqui

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.