I have been having problems with trying to create a timer program using python. I want it so that a user can enter an amount of time for the timer to count down from and update every 0.1 seconds or so. So far I have this code:
from gi.repository import Gtk
import time
import threading
class TimerWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title = "Timer")
self.box = Gtk.Box(spacing = 1)
self.add(self.box)
self.entry = Gtk.Entry()
self.entry.connect("activate", self.start, self.entry)
self.box.pack_start(self.entry, True, True, 0)
def start(self, widget, entry):
starttime = time.time()
totaltime = float(entry.get_text())
self.update(starttime, totaltime, entry)
def update(self, starttime, totaltime, entry):
entry.set_text(str(totaltime - (time.time() - starttime)))
if float(entry.get_text()) > 0:
t = threading.Timer(0.1, self.update, [starttime, totaltime, entry])
t.start()
win = TimerWindow()
win.connect("delete-event", Gtk.main_quit)
win.set_keep_above(True)
win.show_all()
Gtk.main()
This seems to sort of work for a bit, but it sometimes returns this:
timer.py:31: Warning: g_object_ref: assertion 'object->ref_count > 0' failed
Gtk.main()
Segmentation fault
I do not know what causes this, and I need a bit of help. Could someone help me find a way to stop this from happening?