[Python] Dismiss a kivy popup thats created outside the function thats dismissing it

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    Im creating a kivy popup with all available drives. The idea is to click a drive button and than have that directory open in filechooser widget. The only issue is I need to dismiss the drive popup once the directory is opened but I cant reference that popup within my drive function. I have tried to create the popup at the top of the class but that did not work either.

    def filebtn(self):

    global popup
    from functools import partial

    popup_1 = Popup(title="Select drive to access", size_hint=(0.7, 0.7))
    content_layout = BoxLayout(orientation='vertical', spacing=10)
    box_layout = BoxLayout(size=(500, 500))

    if platform == 'win':

    print('platform is windows')

    drives = []
    for letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
    drive_path = f"{letter}:\\"
    if os.path.exists(drive_path):
    drives.append(drive_path)
    print(drives)

    for item in drives:
    btn = Button(text=item)
    btn.bind(on_release=partial(self.get_drive, item))

    content_layout.add_widget(btn)

    popup_1.add_widget(content_layout)

    popup_1.open()

    else:
    popup.open()

    def get_drive(self,item,instance):

    print(f"Button text: {item}")
    MyFileChooser.rootpath = item

    popup = Popup(title='Select Files and click attach when selected, click outside the box to close',
    content=MyFileChooser(),
    # dont need () because they already called the function at the top of class with mc = Myfilechooser()
    size_hint=(0.7, 0.7))
    popup.bind(on_dismiss=lambda attached: self.attach_called())


    popup.open()
    popup_1.dismiss() # problem here

    Continue reading...

Compartilhe esta Página