Sunday, April 28, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 704  / 3 Years ago, wed, may 26, 2021, 8:53:46

I am developing a multithreaded application in pygtk using quickly and stuck with threads. So I am experimenting with various possibilities and found out that my thread work only when I do something in the gui Here is my code



t = threading.Thread(target=self.calc,args=(treeiter))
t.daemon = True
t.start()

def calc(self,treeiter):
store=self.builder.get_object('liststore1')
per=0
while 1:
print "Calcing and changing percent,per="+str(per)
tore.set_value(treeiter,4,str(int(per))+"%")
per+=1
time.sleep(1)


I am trying to update the value in a liststore by thread but it only get update when I click some button or some other gui events why is that so? why is the thread not running in the background?


More From » application-development

 Answers
4

Using time.sleep() is not a good idea when you are using gtk. You could try use a timer event. (I don't use quickly anymore but this should work i think.)



from gi.repository import GLib

class Just_for_correct_coding():
self.per = int()

def start(self):
GLib.timeout_add_seconds(1, self.calc)

def calc(self,treeiter):
store=self.builder.get_object('liststore1')
print "Calcing and changing percent,per="+str(self.per)
tore.set_value(treeiter,4,str(int(self.per))+"%")
self.per+=1
return True #important if you want to keep the timer running

[#31954] Thursday, May 27, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
asketbridiculou

Total Points: 168
Total Questions: 116
Total Answers: 115

Location: Antigua and Barbuda
Member since Sat, Jan 28, 2023
1 Year ago
;