Dynamic system tray text (Python 3)How to build a SystemTray app for Windows?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

Safely hang a mirror that does not have hooks

Would Taiwan and China's dispute be solved if Taiwan gave up being the Republic of China?

Examples of "unsuccessful" theories with afterlives

A drug that allows people to survive on less food

Worms crawling under skin

What is the need of methods like GET and POST in the HTTP protocol?

Counting most common combination of values in dataframe column

How does IBM's 53-bit quantum computer compare to classical ones for cryptanalytic tasks?

The 100 soldier problem

Was there a trial by combat between a man and a dog in medieval France?

Is there any reason nowadays to use a neon indicator lamp instead of an LED?

Do we know the situation in Britain before Sealion (summer 1940)?

Algorithm that spans orthogonal vectors: Python

Can this word order be rearranged?

Do the villains know Batman has no superpowers?

Late 1970's and 6502 chip facilities for operating systems

Will Proving or Disproving of any of the following have effects on Chemistry in general?

How to make interviewee comfortable interviewing in lounge chairs

Does wetting a beer glass change the foam characteristics?

What is the meaning of "heutig" in this sentence?

What can a pilot do if an air traffic controller is incapacitated?

Is it impolite to ask for halal food when traveling to and in Thailand?

Can the U.S. president make military decisions without consulting anyone?

Hiking with a mule or two?



Dynamic system tray text (Python 3)


How to build a SystemTray app for Windows?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to get a dynamic text displayed in the system tray (this will be 2 numbers (from 1 to 100) changing every 2 minutes).



I found this script as a starting point (but I am not commited to it!).



But I get this error :



TypeError: Image.SetData(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'str'
overload 2: argument 1 has unexpected type 'str'
OnInit returned false, exiting...


The relevant part of the code is:



def Get(self,l,r):
s=""+self.s_line
for i in range(5):
if i<(5-l):
sl = self.sl_off
else:
sl = self.sl_on

if i<(5-r):
sr = self.sr_off
else:
sr = self.sr_on

s+=self.s_border+sl+self.s_point+sr+self.s_point
s+=self.s_border+sl+self.s_point+sr+self.s_point
s+=self.s_line

image = wx.EmptyImage(16,16)
image.SetData(s)

bmp = image.ConvertToBitmap()
bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white

icon = wx.EmptyIcon()
icon.CopyFromBitmap(bmp)

return icon


I add to update the script by adding import wx.adv and by replacing the 2 wx.TaskBarIcon by wx.adv.TaskBarIcon.



I am on Windows 10 with Python 3.6










share|improve this question
































    0















    I am trying to get a dynamic text displayed in the system tray (this will be 2 numbers (from 1 to 100) changing every 2 minutes).



    I found this script as a starting point (but I am not commited to it!).



    But I get this error :



    TypeError: Image.SetData(): arguments did not match any overloaded call:
    overload 1: argument 1 has unexpected type 'str'
    overload 2: argument 1 has unexpected type 'str'
    OnInit returned false, exiting...


    The relevant part of the code is:



    def Get(self,l,r):
    s=""+self.s_line
    for i in range(5):
    if i<(5-l):
    sl = self.sl_off
    else:
    sl = self.sl_on

    if i<(5-r):
    sr = self.sr_off
    else:
    sr = self.sr_on

    s+=self.s_border+sl+self.s_point+sr+self.s_point
    s+=self.s_border+sl+self.s_point+sr+self.s_point
    s+=self.s_line

    image = wx.EmptyImage(16,16)
    image.SetData(s)

    bmp = image.ConvertToBitmap()
    bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white

    icon = wx.EmptyIcon()
    icon.CopyFromBitmap(bmp)

    return icon


    I add to update the script by adding import wx.adv and by replacing the 2 wx.TaskBarIcon by wx.adv.TaskBarIcon.



    I am on Windows 10 with Python 3.6










    share|improve this question




























      0












      0








      0








      I am trying to get a dynamic text displayed in the system tray (this will be 2 numbers (from 1 to 100) changing every 2 minutes).



      I found this script as a starting point (but I am not commited to it!).



      But I get this error :



      TypeError: Image.SetData(): arguments did not match any overloaded call:
      overload 1: argument 1 has unexpected type 'str'
      overload 2: argument 1 has unexpected type 'str'
      OnInit returned false, exiting...


      The relevant part of the code is:



      def Get(self,l,r):
      s=""+self.s_line
      for i in range(5):
      if i<(5-l):
      sl = self.sl_off
      else:
      sl = self.sl_on

      if i<(5-r):
      sr = self.sr_off
      else:
      sr = self.sr_on

      s+=self.s_border+sl+self.s_point+sr+self.s_point
      s+=self.s_border+sl+self.s_point+sr+self.s_point
      s+=self.s_line

      image = wx.EmptyImage(16,16)
      image.SetData(s)

      bmp = image.ConvertToBitmap()
      bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white

      icon = wx.EmptyIcon()
      icon.CopyFromBitmap(bmp)

      return icon


      I add to update the script by adding import wx.adv and by replacing the 2 wx.TaskBarIcon by wx.adv.TaskBarIcon.



      I am on Windows 10 with Python 3.6










      share|improve this question
















      I am trying to get a dynamic text displayed in the system tray (this will be 2 numbers (from 1 to 100) changing every 2 minutes).



      I found this script as a starting point (but I am not commited to it!).



      But I get this error :



      TypeError: Image.SetData(): arguments did not match any overloaded call:
      overload 1: argument 1 has unexpected type 'str'
      overload 2: argument 1 has unexpected type 'str'
      OnInit returned false, exiting...


      The relevant part of the code is:



      def Get(self,l,r):
      s=""+self.s_line
      for i in range(5):
      if i<(5-l):
      sl = self.sl_off
      else:
      sl = self.sl_on

      if i<(5-r):
      sr = self.sr_off
      else:
      sr = self.sr_on

      s+=self.s_border+sl+self.s_point+sr+self.s_point
      s+=self.s_border+sl+self.s_point+sr+self.s_point
      s+=self.s_line

      image = wx.EmptyImage(16,16)
      image.SetData(s)

      bmp = image.ConvertToBitmap()
      bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white

      icon = wx.EmptyIcon()
      icon.CopyFromBitmap(bmp)

      return icon


      I add to update the script by adding import wx.adv and by replacing the 2 wx.TaskBarIcon by wx.adv.TaskBarIcon.



      I am on Windows 10 with Python 3.6







      python python-3.x wxpython system-tray






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 16:08







      MagTun

















      asked Mar 27 at 15:34









      MagTunMagTun

      2,4662 gold badges27 silver badges51 bronze badges




      2,4662 gold badges27 silver badges51 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1
















          I found another way using Pillow and infi.systray



          # text to image : Pillow (https://pillow.readthedocs.io/en/latest/handbook/tutorial.html - simple code sample: https://code-maven.com/create-images-with-python-pil-pillow)
          # icon in systray : infi.systray (https://github.com/Infinidat/infi.systray and https://stackoverflow.com/a/54082417/3154274)

          # inspired by https://www.reddit.com/r/learnpython/comments/a7utd7/pystray_python_system_tray_icon_app/

          # install PIL : pip install Pillow
          # install infi.systray : pip install infi.systray

          from infi.systray import SysTrayIcon
          from PIL import Image, ImageDraw,ImageFont
          import time

          image= "pil_text.ico"
          n=1
          while True:
          # create image
          img = Image.new('RGBA', (50, 50), color = (255, 255, 255, 90)) # color background = white with transparency
          d = ImageDraw.Draw(img)
          d.rectangle([(0, 40), (50, 50)], fill=(39, 112, 229), outline=None) # color = blue

          #add text to the image
          font_type = ImageFont.truetype("arial.ttf", 25)
          a= n*10
          b = n*20
          d.text((0,0), f"anb", fill=(255,255,0), font = font_type)

          img.save(image)


          # display image in systray
          if n==1:
          systray = SysTrayIcon(image, "Systray")
          systray.start()
          else:
          systray.update(icon=image)
          time.sleep(5)
          n+=1
          systray.shutdown()


          enter image description here






          share|improve this answer


































            0
















            The following uses the current minute and second as a replacement for your line numbers but can be easily adapted.



            import wx
            import wx.adv
            import datetime
            from wx.lib.embeddedimage import PyEmbeddedImage
            #
            # A white box 28x28 pixels
            #
            toggletest = PyEmbeddedImage(
            b'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAIAAAD9b0jDAAAACXBIWXMAAAsTAAALEwEAmpwY'
            b'AAAAB3RJTUUH4wMfCgElTFaeRQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJ'
            b'TVBkLmUHAAAAKElEQVRIx2P8//8/A7UBEwMNwKiho4aOGjpq6Kiho4aOGjpq6OAzFADRYgM1'
            b'8cIRtgAAAABJRU5ErkJggg==')

            class TaskBarIcon(wx.adv.TaskBarIcon):
            def __init__(self, frame):
            self.frame = frame
            self.toggle = 0
            wx.adv.TaskBarIcon.__init__(self)
            self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnToggle)
            self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
            self.font.SetPointSize(8)
            self.OnSetIcon(self.NewIcon())

            def CreatePopupMenu(self):
            menu = wx.Menu()
            togglem = wx.MenuItem(menu, wx.NewId(), 'Toggle Icon')
            menu.Bind(wx.EVT_MENU, self.OnToggle, id=togglem.GetId())
            menu.Append(togglem)
            menu.AppendSeparator()
            flashm = wx.MenuItem(menu, wx.NewId(), 'Flashing Icon')
            menu.Bind(wx.EVT_MENU, self.OnTimer, id=flashm.GetId())
            menu.Append(flashm)
            menu.AppendSeparator()
            quitm = wx.MenuItem(menu, wx.NewId(), 'Quit')
            menu.Bind(wx.EVT_MENU, self.OnQuit, id=quitm.GetId())
            menu.Append(quitm)
            return menu

            def NewIcon(self):
            bitmap = wx.Bitmap(toggletest.Bitmap)
            dc = wx.MemoryDC(bitmap)
            # Use current time as text, for want of something useful
            now = datetime.datetime.today()
            text = str(now.minute)+"n"+str(now.second)
            dc.SetFont(self.font)
            dc.DrawText(text, 2, 2)
            del dc
            return bitmap

            def OnSetIcon(self, bitmap):
            icon = wx.Icon()
            icon.CopyFromBitmap(bitmap)
            self.SetIcon(icon)

            def OnToggle(self, event):
            bitmap = self.NewIcon()
            self.OnSetIcon(bitmap)

            def OnTimer(self,event):
            self.timer = wx.Timer(self)
            self.Bind(wx.EVT_TIMER, self.OnUseTimer)
            self.timer.Start(1000)

            def OnUseTimer(self,event):
            self.OnToggle(None)

            def OnQuit(self, event):
            self.RemoveIcon()
            wx.CallAfter(self.Destroy)
            self.frame.Close()

            if __name__ == '__main__':
            app = wx.App()
            frame=wx.Frame(None)
            TaskBarIcon(frame)
            app.MainLoop()


            The result is the white box below with 22 above 33



            enter image description here






            share|improve this answer



























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );














              draft saved

              draft discarded
















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381039%2fdynamic-system-tray-text-python-3%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1
















              I found another way using Pillow and infi.systray



              # text to image : Pillow (https://pillow.readthedocs.io/en/latest/handbook/tutorial.html - simple code sample: https://code-maven.com/create-images-with-python-pil-pillow)
              # icon in systray : infi.systray (https://github.com/Infinidat/infi.systray and https://stackoverflow.com/a/54082417/3154274)

              # inspired by https://www.reddit.com/r/learnpython/comments/a7utd7/pystray_python_system_tray_icon_app/

              # install PIL : pip install Pillow
              # install infi.systray : pip install infi.systray

              from infi.systray import SysTrayIcon
              from PIL import Image, ImageDraw,ImageFont
              import time

              image= "pil_text.ico"
              n=1
              while True:
              # create image
              img = Image.new('RGBA', (50, 50), color = (255, 255, 255, 90)) # color background = white with transparency
              d = ImageDraw.Draw(img)
              d.rectangle([(0, 40), (50, 50)], fill=(39, 112, 229), outline=None) # color = blue

              #add text to the image
              font_type = ImageFont.truetype("arial.ttf", 25)
              a= n*10
              b = n*20
              d.text((0,0), f"anb", fill=(255,255,0), font = font_type)

              img.save(image)


              # display image in systray
              if n==1:
              systray = SysTrayIcon(image, "Systray")
              systray.start()
              else:
              systray.update(icon=image)
              time.sleep(5)
              n+=1
              systray.shutdown()


              enter image description here






              share|improve this answer































                1
















                I found another way using Pillow and infi.systray



                # text to image : Pillow (https://pillow.readthedocs.io/en/latest/handbook/tutorial.html - simple code sample: https://code-maven.com/create-images-with-python-pil-pillow)
                # icon in systray : infi.systray (https://github.com/Infinidat/infi.systray and https://stackoverflow.com/a/54082417/3154274)

                # inspired by https://www.reddit.com/r/learnpython/comments/a7utd7/pystray_python_system_tray_icon_app/

                # install PIL : pip install Pillow
                # install infi.systray : pip install infi.systray

                from infi.systray import SysTrayIcon
                from PIL import Image, ImageDraw,ImageFont
                import time

                image= "pil_text.ico"
                n=1
                while True:
                # create image
                img = Image.new('RGBA', (50, 50), color = (255, 255, 255, 90)) # color background = white with transparency
                d = ImageDraw.Draw(img)
                d.rectangle([(0, 40), (50, 50)], fill=(39, 112, 229), outline=None) # color = blue

                #add text to the image
                font_type = ImageFont.truetype("arial.ttf", 25)
                a= n*10
                b = n*20
                d.text((0,0), f"anb", fill=(255,255,0), font = font_type)

                img.save(image)


                # display image in systray
                if n==1:
                systray = SysTrayIcon(image, "Systray")
                systray.start()
                else:
                systray.update(icon=image)
                time.sleep(5)
                n+=1
                systray.shutdown()


                enter image description here






                share|improve this answer





























                  1














                  1










                  1









                  I found another way using Pillow and infi.systray



                  # text to image : Pillow (https://pillow.readthedocs.io/en/latest/handbook/tutorial.html - simple code sample: https://code-maven.com/create-images-with-python-pil-pillow)
                  # icon in systray : infi.systray (https://github.com/Infinidat/infi.systray and https://stackoverflow.com/a/54082417/3154274)

                  # inspired by https://www.reddit.com/r/learnpython/comments/a7utd7/pystray_python_system_tray_icon_app/

                  # install PIL : pip install Pillow
                  # install infi.systray : pip install infi.systray

                  from infi.systray import SysTrayIcon
                  from PIL import Image, ImageDraw,ImageFont
                  import time

                  image= "pil_text.ico"
                  n=1
                  while True:
                  # create image
                  img = Image.new('RGBA', (50, 50), color = (255, 255, 255, 90)) # color background = white with transparency
                  d = ImageDraw.Draw(img)
                  d.rectangle([(0, 40), (50, 50)], fill=(39, 112, 229), outline=None) # color = blue

                  #add text to the image
                  font_type = ImageFont.truetype("arial.ttf", 25)
                  a= n*10
                  b = n*20
                  d.text((0,0), f"anb", fill=(255,255,0), font = font_type)

                  img.save(image)


                  # display image in systray
                  if n==1:
                  systray = SysTrayIcon(image, "Systray")
                  systray.start()
                  else:
                  systray.update(icon=image)
                  time.sleep(5)
                  n+=1
                  systray.shutdown()


                  enter image description here






                  share|improve this answer















                  I found another way using Pillow and infi.systray



                  # text to image : Pillow (https://pillow.readthedocs.io/en/latest/handbook/tutorial.html - simple code sample: https://code-maven.com/create-images-with-python-pil-pillow)
                  # icon in systray : infi.systray (https://github.com/Infinidat/infi.systray and https://stackoverflow.com/a/54082417/3154274)

                  # inspired by https://www.reddit.com/r/learnpython/comments/a7utd7/pystray_python_system_tray_icon_app/

                  # install PIL : pip install Pillow
                  # install infi.systray : pip install infi.systray

                  from infi.systray import SysTrayIcon
                  from PIL import Image, ImageDraw,ImageFont
                  import time

                  image= "pil_text.ico"
                  n=1
                  while True:
                  # create image
                  img = Image.new('RGBA', (50, 50), color = (255, 255, 255, 90)) # color background = white with transparency
                  d = ImageDraw.Draw(img)
                  d.rectangle([(0, 40), (50, 50)], fill=(39, 112, 229), outline=None) # color = blue

                  #add text to the image
                  font_type = ImageFont.truetype("arial.ttf", 25)
                  a= n*10
                  b = n*20
                  d.text((0,0), f"anb", fill=(255,255,0), font = font_type)

                  img.save(image)


                  # display image in systray
                  if n==1:
                  systray = SysTrayIcon(image, "Systray")
                  systray.start()
                  else:
                  systray.update(icon=image)
                  time.sleep(5)
                  n+=1
                  systray.shutdown()


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 28 at 16:12

























                  answered Mar 27 at 16:07









                  MagTunMagTun

                  2,4662 gold badges27 silver badges51 bronze badges




                  2,4662 gold badges27 silver badges51 bronze badges


























                      0
















                      The following uses the current minute and second as a replacement for your line numbers but can be easily adapted.



                      import wx
                      import wx.adv
                      import datetime
                      from wx.lib.embeddedimage import PyEmbeddedImage
                      #
                      # A white box 28x28 pixels
                      #
                      toggletest = PyEmbeddedImage(
                      b'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAIAAAD9b0jDAAAACXBIWXMAAAsTAAALEwEAmpwY'
                      b'AAAAB3RJTUUH4wMfCgElTFaeRQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJ'
                      b'TVBkLmUHAAAAKElEQVRIx2P8//8/A7UBEwMNwKiho4aOGjpq6Kiho4aOGjpq6OAzFADRYgM1'
                      b'8cIRtgAAAABJRU5ErkJggg==')

                      class TaskBarIcon(wx.adv.TaskBarIcon):
                      def __init__(self, frame):
                      self.frame = frame
                      self.toggle = 0
                      wx.adv.TaskBarIcon.__init__(self)
                      self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnToggle)
                      self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
                      self.font.SetPointSize(8)
                      self.OnSetIcon(self.NewIcon())

                      def CreatePopupMenu(self):
                      menu = wx.Menu()
                      togglem = wx.MenuItem(menu, wx.NewId(), 'Toggle Icon')
                      menu.Bind(wx.EVT_MENU, self.OnToggle, id=togglem.GetId())
                      menu.Append(togglem)
                      menu.AppendSeparator()
                      flashm = wx.MenuItem(menu, wx.NewId(), 'Flashing Icon')
                      menu.Bind(wx.EVT_MENU, self.OnTimer, id=flashm.GetId())
                      menu.Append(flashm)
                      menu.AppendSeparator()
                      quitm = wx.MenuItem(menu, wx.NewId(), 'Quit')
                      menu.Bind(wx.EVT_MENU, self.OnQuit, id=quitm.GetId())
                      menu.Append(quitm)
                      return menu

                      def NewIcon(self):
                      bitmap = wx.Bitmap(toggletest.Bitmap)
                      dc = wx.MemoryDC(bitmap)
                      # Use current time as text, for want of something useful
                      now = datetime.datetime.today()
                      text = str(now.minute)+"n"+str(now.second)
                      dc.SetFont(self.font)
                      dc.DrawText(text, 2, 2)
                      del dc
                      return bitmap

                      def OnSetIcon(self, bitmap):
                      icon = wx.Icon()
                      icon.CopyFromBitmap(bitmap)
                      self.SetIcon(icon)

                      def OnToggle(self, event):
                      bitmap = self.NewIcon()
                      self.OnSetIcon(bitmap)

                      def OnTimer(self,event):
                      self.timer = wx.Timer(self)
                      self.Bind(wx.EVT_TIMER, self.OnUseTimer)
                      self.timer.Start(1000)

                      def OnUseTimer(self,event):
                      self.OnToggle(None)

                      def OnQuit(self, event):
                      self.RemoveIcon()
                      wx.CallAfter(self.Destroy)
                      self.frame.Close()

                      if __name__ == '__main__':
                      app = wx.App()
                      frame=wx.Frame(None)
                      TaskBarIcon(frame)
                      app.MainLoop()


                      The result is the white box below with 22 above 33



                      enter image description here






                      share|improve this answer





























                        0
















                        The following uses the current minute and second as a replacement for your line numbers but can be easily adapted.



                        import wx
                        import wx.adv
                        import datetime
                        from wx.lib.embeddedimage import PyEmbeddedImage
                        #
                        # A white box 28x28 pixels
                        #
                        toggletest = PyEmbeddedImage(
                        b'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAIAAAD9b0jDAAAACXBIWXMAAAsTAAALEwEAmpwY'
                        b'AAAAB3RJTUUH4wMfCgElTFaeRQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJ'
                        b'TVBkLmUHAAAAKElEQVRIx2P8//8/A7UBEwMNwKiho4aOGjpq6Kiho4aOGjpq6OAzFADRYgM1'
                        b'8cIRtgAAAABJRU5ErkJggg==')

                        class TaskBarIcon(wx.adv.TaskBarIcon):
                        def __init__(self, frame):
                        self.frame = frame
                        self.toggle = 0
                        wx.adv.TaskBarIcon.__init__(self)
                        self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnToggle)
                        self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
                        self.font.SetPointSize(8)
                        self.OnSetIcon(self.NewIcon())

                        def CreatePopupMenu(self):
                        menu = wx.Menu()
                        togglem = wx.MenuItem(menu, wx.NewId(), 'Toggle Icon')
                        menu.Bind(wx.EVT_MENU, self.OnToggle, id=togglem.GetId())
                        menu.Append(togglem)
                        menu.AppendSeparator()
                        flashm = wx.MenuItem(menu, wx.NewId(), 'Flashing Icon')
                        menu.Bind(wx.EVT_MENU, self.OnTimer, id=flashm.GetId())
                        menu.Append(flashm)
                        menu.AppendSeparator()
                        quitm = wx.MenuItem(menu, wx.NewId(), 'Quit')
                        menu.Bind(wx.EVT_MENU, self.OnQuit, id=quitm.GetId())
                        menu.Append(quitm)
                        return menu

                        def NewIcon(self):
                        bitmap = wx.Bitmap(toggletest.Bitmap)
                        dc = wx.MemoryDC(bitmap)
                        # Use current time as text, for want of something useful
                        now = datetime.datetime.today()
                        text = str(now.minute)+"n"+str(now.second)
                        dc.SetFont(self.font)
                        dc.DrawText(text, 2, 2)
                        del dc
                        return bitmap

                        def OnSetIcon(self, bitmap):
                        icon = wx.Icon()
                        icon.CopyFromBitmap(bitmap)
                        self.SetIcon(icon)

                        def OnToggle(self, event):
                        bitmap = self.NewIcon()
                        self.OnSetIcon(bitmap)

                        def OnTimer(self,event):
                        self.timer = wx.Timer(self)
                        self.Bind(wx.EVT_TIMER, self.OnUseTimer)
                        self.timer.Start(1000)

                        def OnUseTimer(self,event):
                        self.OnToggle(None)

                        def OnQuit(self, event):
                        self.RemoveIcon()
                        wx.CallAfter(self.Destroy)
                        self.frame.Close()

                        if __name__ == '__main__':
                        app = wx.App()
                        frame=wx.Frame(None)
                        TaskBarIcon(frame)
                        app.MainLoop()


                        The result is the white box below with 22 above 33



                        enter image description here






                        share|improve this answer



























                          0














                          0










                          0









                          The following uses the current minute and second as a replacement for your line numbers but can be easily adapted.



                          import wx
                          import wx.adv
                          import datetime
                          from wx.lib.embeddedimage import PyEmbeddedImage
                          #
                          # A white box 28x28 pixels
                          #
                          toggletest = PyEmbeddedImage(
                          b'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAIAAAD9b0jDAAAACXBIWXMAAAsTAAALEwEAmpwY'
                          b'AAAAB3RJTUUH4wMfCgElTFaeRQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJ'
                          b'TVBkLmUHAAAAKElEQVRIx2P8//8/A7UBEwMNwKiho4aOGjpq6Kiho4aOGjpq6OAzFADRYgM1'
                          b'8cIRtgAAAABJRU5ErkJggg==')

                          class TaskBarIcon(wx.adv.TaskBarIcon):
                          def __init__(self, frame):
                          self.frame = frame
                          self.toggle = 0
                          wx.adv.TaskBarIcon.__init__(self)
                          self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnToggle)
                          self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
                          self.font.SetPointSize(8)
                          self.OnSetIcon(self.NewIcon())

                          def CreatePopupMenu(self):
                          menu = wx.Menu()
                          togglem = wx.MenuItem(menu, wx.NewId(), 'Toggle Icon')
                          menu.Bind(wx.EVT_MENU, self.OnToggle, id=togglem.GetId())
                          menu.Append(togglem)
                          menu.AppendSeparator()
                          flashm = wx.MenuItem(menu, wx.NewId(), 'Flashing Icon')
                          menu.Bind(wx.EVT_MENU, self.OnTimer, id=flashm.GetId())
                          menu.Append(flashm)
                          menu.AppendSeparator()
                          quitm = wx.MenuItem(menu, wx.NewId(), 'Quit')
                          menu.Bind(wx.EVT_MENU, self.OnQuit, id=quitm.GetId())
                          menu.Append(quitm)
                          return menu

                          def NewIcon(self):
                          bitmap = wx.Bitmap(toggletest.Bitmap)
                          dc = wx.MemoryDC(bitmap)
                          # Use current time as text, for want of something useful
                          now = datetime.datetime.today()
                          text = str(now.minute)+"n"+str(now.second)
                          dc.SetFont(self.font)
                          dc.DrawText(text, 2, 2)
                          del dc
                          return bitmap

                          def OnSetIcon(self, bitmap):
                          icon = wx.Icon()
                          icon.CopyFromBitmap(bitmap)
                          self.SetIcon(icon)

                          def OnToggle(self, event):
                          bitmap = self.NewIcon()
                          self.OnSetIcon(bitmap)

                          def OnTimer(self,event):
                          self.timer = wx.Timer(self)
                          self.Bind(wx.EVT_TIMER, self.OnUseTimer)
                          self.timer.Start(1000)

                          def OnUseTimer(self,event):
                          self.OnToggle(None)

                          def OnQuit(self, event):
                          self.RemoveIcon()
                          wx.CallAfter(self.Destroy)
                          self.frame.Close()

                          if __name__ == '__main__':
                          app = wx.App()
                          frame=wx.Frame(None)
                          TaskBarIcon(frame)
                          app.MainLoop()


                          The result is the white box below with 22 above 33



                          enter image description here






                          share|improve this answer













                          The following uses the current minute and second as a replacement for your line numbers but can be easily adapted.



                          import wx
                          import wx.adv
                          import datetime
                          from wx.lib.embeddedimage import PyEmbeddedImage
                          #
                          # A white box 28x28 pixels
                          #
                          toggletest = PyEmbeddedImage(
                          b'iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAIAAAD9b0jDAAAACXBIWXMAAAsTAAALEwEAmpwY'
                          b'AAAAB3RJTUUH4wMfCgElTFaeRQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJ'
                          b'TVBkLmUHAAAAKElEQVRIx2P8//8/A7UBEwMNwKiho4aOGjpq6Kiho4aOGjpq6OAzFADRYgM1'
                          b'8cIRtgAAAABJRU5ErkJggg==')

                          class TaskBarIcon(wx.adv.TaskBarIcon):
                          def __init__(self, frame):
                          self.frame = frame
                          self.toggle = 0
                          wx.adv.TaskBarIcon.__init__(self)
                          self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnToggle)
                          self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
                          self.font.SetPointSize(8)
                          self.OnSetIcon(self.NewIcon())

                          def CreatePopupMenu(self):
                          menu = wx.Menu()
                          togglem = wx.MenuItem(menu, wx.NewId(), 'Toggle Icon')
                          menu.Bind(wx.EVT_MENU, self.OnToggle, id=togglem.GetId())
                          menu.Append(togglem)
                          menu.AppendSeparator()
                          flashm = wx.MenuItem(menu, wx.NewId(), 'Flashing Icon')
                          menu.Bind(wx.EVT_MENU, self.OnTimer, id=flashm.GetId())
                          menu.Append(flashm)
                          menu.AppendSeparator()
                          quitm = wx.MenuItem(menu, wx.NewId(), 'Quit')
                          menu.Bind(wx.EVT_MENU, self.OnQuit, id=quitm.GetId())
                          menu.Append(quitm)
                          return menu

                          def NewIcon(self):
                          bitmap = wx.Bitmap(toggletest.Bitmap)
                          dc = wx.MemoryDC(bitmap)
                          # Use current time as text, for want of something useful
                          now = datetime.datetime.today()
                          text = str(now.minute)+"n"+str(now.second)
                          dc.SetFont(self.font)
                          dc.DrawText(text, 2, 2)
                          del dc
                          return bitmap

                          def OnSetIcon(self, bitmap):
                          icon = wx.Icon()
                          icon.CopyFromBitmap(bitmap)
                          self.SetIcon(icon)

                          def OnToggle(self, event):
                          bitmap = self.NewIcon()
                          self.OnSetIcon(bitmap)

                          def OnTimer(self,event):
                          self.timer = wx.Timer(self)
                          self.Bind(wx.EVT_TIMER, self.OnUseTimer)
                          self.timer.Start(1000)

                          def OnUseTimer(self,event):
                          self.OnToggle(None)

                          def OnQuit(self, event):
                          self.RemoveIcon()
                          wx.CallAfter(self.Destroy)
                          self.frame.Close()

                          if __name__ == '__main__':
                          app = wx.App()
                          frame=wx.Frame(None)
                          TaskBarIcon(frame)
                          app.MainLoop()


                          The result is the white box below with 22 above 33



                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 31 at 11:01









                          Rolf of SaxonyRolf of Saxony

                          11.9k2 gold badges23 silver badges40 bronze badges




                          11.9k2 gold badges23 silver badges40 bronze badges































                              draft saved

                              draft discarded















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381039%2fdynamic-system-tray-text-python-3%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript