1

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!

Leonardo Freua
  • 123
  • 1
  • 1
  • 7
  • Maybe [this](https://www.learnpyqt.com/courses/adanced-ui-features/system-tray-mac-menu-bar-applications-pyqt/) is what you're looking for? – nathancy Sep 18 '19 at 22:19
  • don't use infinity loop in any GUI framework. Most GUI has some method to run code periodically and not block other elements (like `mainloop`/`event loop` which has to loop all time). As I remeber `PyQt` has `QTimer` for this. – furas Sep 18 '19 at 23:00
  • @nathancy, I tried wth this one, but I can't because I'm using infinite loop. I will try using this tutorial again, matching the furas tip. Thanks for the help from both. – Leonardo Freua Sep 18 '19 at 23:22

1 Answers1

0

I was able to solve using QTimer of PyQT. The question below is exactly what I needed:

threading for tray icon application

Leonardo Freua
  • 123
  • 1
  • 1
  • 7