Search code examples
pythonwindowsnotificationspywin32system-tray

How to add line breaks to a Windows notification balloon?


I have a tray bar application that displays notifications. Those are the regular Windows notifications, as a balloon over the application icon.

This is the basic code:

class TrayIconApplication:
    def __init__(self):
        [very long code to setup instance]

    def notify(self, message, title):
        Shell_NotifyIcon(NIM_MODIFY,
                         (self.hwnd, 0, NIF_INFO, WM_USER + 20,
                          self.hicon, 'Balloon Tooltip', message, 200,
                          title))

How do I add line breaks to the message, making it appear in multiple lines? I've tried \n and \r\n, but they don't seem to affect the text. \r alones is displayed as a single space and \t works as expected, but all messages are still displayed in only a single line.

Combinations of \r and \n, as well as their repetition, didn't yield any results.


Solution

  • I was changing the title, not the message. I mixed the order of parameters and was displaying a notification with title but empty message. And title lines cannot be broken, so it was ignoring all my attempts.

    The difference is that the title is slightly larger, blue, and displayed in the same line as the close button.

    As soon as I switched the parameters, \n started being accepted as the line break character and displaying a multi line balloon notification.