Displaying transient notifications
If your application needs to occasionally get the user's attention and present some information that may not be critical or require acknowledgement, the ToasterBox
window can be a nice and unobtrusive way to show simple messages to the user. In this recipe, we will make a small TrayIcon
application that acts as a timer, which pops up a notification every time a set amount of time has elapsed.
How to do it…
Here are the steps that you need to perform:
First, we need an additional import from
wx.lib
to accessToasterBox
. For this, we will uses the following code:import wx import wx.lib.agw.toasterbox as tb ID_GET_DUR = wx.NewId() ID_START = wx.NewId()
Next, let's make a custom
TaskBarIcon
object to manage our alarm notifications, as follows:class AlarmIcon(wx.TaskBarIcon): def __init__(self, topWindow): super(AlarmIcon, self).__init__() self._topWindow = topWindow self._timer = wx.Timer(self) self._duration = 10 ...