I am trying to create a Tray icon with Python on Ubuntu Linux (this is not important, but it is for more details). I need my small system to show an Icon (Image) according to the result (Boolean) returned from a method. All this within an infinite loop, checking every 5 minutes, ie a status icon that updates according to the return of the method.
I tried with several different libraries, such as: PyQt5.QtGui
, PyQt5.QtWidgets
, PySimpleGUIQt
, pystray
. All of these execute a command that prevents the infinite loop from running after the first iteration. The command is: app.exec_()
Code example:
def check_network_status():
try:
requests.get('http://google.com.br/')
return True
excepte:
return False
while True:
if check_network_status():
# show online icon
else:
# show offline icon
thank you in advance for any help!
I was able to solve using QTimer of PyQT. The question below is exactly what I needed: