Show a notification message on the desktop (Phoenix)

Keywords : Pop up, Notification, Message.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


First example

img_sample_one.png

ICON file : wxwin.ico

   1 # sample_one.py
   2 
   3 import os
   4 import wx
   5 import wx.adv
   6 
   7 # class MyFrame
   8 # class MyApp
   9 
  10 #---------------------------------------------------------------------------
  11 
  12 class MyFrame(wx.Frame):
  13     def __init__(self):
  14         wx.Frame.__init__(self, None, title=wx.GetApp().GetAppName())
  15         self.SetIcon(wx.Icon('wxwin.ico'))
  16 
  17         self._createControls()
  18 
  19         self._connectControls()
  20 
  21     def _createControls(self):
  22         # A Statusbar in the bottom of the window
  23         self.CreateStatusBar(1)
  24         sMsg = 'wxPython ' + wx.version()
  25         self.SetStatusText(sMsg)
  26 
  27         # Add a panel to the frame (needed under Windows to have a nice background)
  28         pnl = wx.Panel(self, wx.ID_ANY)
  29 
  30         szrMain = wx.BoxSizer(wx.VERTICAL)
  31         szrMain.AddStretchSpacer(1)
  32         self._btnShowMsg = wx.Button(pnl, wx.ID_ANY, 'Show a notification message')
  33         szrMain.Add(self._btnShowMsg, 0, wx.ALL|wx.ALIGN_CENTER, 5)
  34         szrMain.AddStretchSpacer(1)
  35         pnl.SetSizer(szrMain)
  36 
  37     def _connectControls(self):
  38         self._btnShowMsg.Bind(wx.EVT_BUTTON, self._onBtnShowMsgClicked)
  39 
  40     def _onBtnShowMsgClicked(self, evt):
  41         sTitle = 'wxWidgets notification'
  42         sMsg = 'This is a notification message.\n\nWelcome on wxWidgets ;-)'
  43 
  44         nmsg = wx.adv.NotificationMessage(title=sTitle, message=sMsg)
  45         nmsg.SetFlags(wx.ICON_INFORMATION)
  46 
  47         nmsg.Show(timeout=wx.adv.NotificationMessage.Timeout_Auto)
  48 
  49 #---------------------------------------------------------------------------
  50 
  51 class MyApp(wx.App):
  52     def OnInit(self):
  53         print('Running wxPython ' + wx.version())
  54         # Set Current directory to the one containing this file
  55         os.chdir(os.path.dirname(os.path.abspath(__file__)))
  56 
  57         self.SetAppName('NotifMsg')
  58 
  59         # Create the main window
  60         frm = MyFrame()
  61         self.SetTopWindow(frm)
  62 
  63         frm.Show()
  64         return True
  65 
  66 #---------------------------------------------------------------------------
  67 
  68 if __name__ == '__main__':
  69     app = MyApp()
  70     app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Xaviou (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

28/08/19 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

Show a notification message on the desktop (Phoenix) (last edited 2020-10-07 10:20:02 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.