Addding widgets from another thread

25 views
Skip to first unread message

Gabriel Lins

unread,
Jun 22, 2017, 1:37:30 PM6/22/17
to kivy-...@googlegroups.com
Hi.

I'm adding widgets based on a HTTP Request that may take long depending on user's internet connection, so I'm in need of threading that to avoid GUI freezing.
However, can't seem to make it work. Here is a snippet of the current code:
@mainthread
def add_w(self, parent, widget):
    parent
.add_widget(widget)

def add_course():
       
# HTTP Request I mentioned
        course
= course_manager.get_course(textfield_text) # This may take some time

        courses_stack_layout
= constructor_screen.ids.added_courses_stack_layout
        course_information_widget
= CourseInformation(coursename_label=course.name)

       
self.add_w(courses_stack_layout, course_information_widget)

The result: sometimes really weird stuff happens. Sometimes.

I have also tried with Clock.schedule_once and Clock.schedule_interval with a Queue. 
Same problem happened. 

Any hints? 


Thanks!

 - Gabriel

Alexander Taylor

unread,
Jun 22, 2017, 2:02:03 PM6/22/17
to Kivy users support
Try moving the widget instantiation to the add_w function. Right now you're creating the widget in the thread, which may cause the problems to occur.

Gabriel Lins

unread,
Jun 22, 2017, 3:33:06 PM6/22/17
to Kivy users support

Holy shit. You're a god.
Many thanks!
Reply all
Reply to author
Forward
0 new messages