Andrey Pa
Andrey Pa

Reputation: 1

Why can't I dismiss kivy popup with function

Why can't I dismiss kivy popup in function. But if try do directly it's working

press() function is working, and print data, but not closing a popup.

 def random_range():
            """open random range function"""
            rangelist = list(range(80))
            random.shuffle(rangelist)
            filllist = [17, 40, 56, 63]
            for i in rangelist:
                if i in filllist:
                    continue
                def press(obj):
                    """button press function"""
                    user_answer = str(obj.text)[0]
                    print(right_answerc)
                    print(user_answer)
                    self.popup.dismiss
                    return 
                main_boxlayout = BoxLayout(orientation='vertical')
                num, header, body, right_answerc = question(i)
                self.popup = Popup(title ='Test popup',
                                   content = main_boxlayout, auto_dismiss = False)
                main_boxlayout.add_widget(Label(text = str(num))) #question number
                main_boxlayout.add_widget(Label(text = str(header))) #question header
                main_boxlayout.add_widget(Label(text = str(right_answerc))) #right answer
                right_answer = (Label(text = str(right_answerc)))
                main_boxlayout.add_widget(right_answer)
                self.main_label = (Label(text = "Your input"))
                main_boxlayout.add_widget(self.main_label)
                button1 = (Button(text = str(body[0])))
                button1.bind(on_press = press)
                button2 = (Button(text = str(body[1])))
                button2.bind(on_press = press)
                button3 = (Button(text = str(body[2])))
                button3.bind(on_press = press)
                button4 = (Button(text = str(body[3])))
                button4.bind(on_press = press)
                button5 = (Button(text = str(body[4])))
                button5.bind(on_press = press)
                button6 = (Button(text = "Next question" ))

but this button is working

                button6.bind(on_release = self.popup.dismiss)
                main_boxlayout.add_widget(button1)
                main_boxlayout.add_widget(button2)
                main_boxlayout.add_widget(button3)
                main_boxlayout.add_widget(button4)
                main_boxlayout.add_widget(button5)
                main_boxlayout.add_widget(button6)
                self.popup.open()

        random_range()

All other options, without success

Upvotes: 0

Views: 35

Answers (0)

Related Questions