Skip to content

Instantly share code, notes, and snippets.

@hygull
Last active June 9, 2023 23:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hygull/32a742339a416dcfa2990504c848c1a9 to your computer and use it in GitHub Desktop.
Save hygull/32a742339a416dcfa2990504c848c1a9 to your computer and use it in GitHub Desktop.
Generating toast notifications on windows 10 using Python

Generating toast notifications on windows 10 using Python

Steps:-

Visit this link https://github.com/jithurjacob/Windows-10-Toast-Notifications to read in more detail.

Create any folder somewhere in your system

Eg. I created in D drive using command mkdir D:\Python2.7

Download ico image

I downloaded Downloads-Black-Folder.ico and save it inside D:\Python2.7 as Downloads-Black-Folder.ico

Navigate inside the directory

Please open command terminal(Press Win + S => Type cmd => Right click on Command prompt option => Clcik on Run as Administrator) as an Administrator

then run cd D:\Python2.7 && D: to navigate inside the directory.

Install win10toast

Run pip install win10toast on terminal to install the package.

Now

Do any one of the following 2 ways according to your wish

  1. Copy the below code and paste on terminal

NOTE: Type python and hit ENTER to start the Python interpreter.

from win10toast import ToastNotifier
import time

toaster = ToastNotifier()
toaster.show_toast("Hello Programmers!!!",
                   "Python is really awesome, I am here for 10 seconds!",
                   icon_path="Downloads-Black-Folder.ico",
                   duration=10)

toaster.show_toast("Good morning Dear",
                   "How are you today?",
                   icon_path=None,
                   duration=5,
                   threaded=True)

# Wait for threaded notification to finish
while toaster.notification_active(): 
    time.sleep(0.1)

Command history

C:\Windows\System32>pip install win10toast
Collecting win10toast
  Using cached win10toast-0.9-py2.py3-none-any.whl
Requirement already satisfied: pypiwin32 in c:\anacondapython2.5.0.1\lib\site-packages (from win10toast)
Requirement already satisfied: setuptools in c:\anacondapython2.5.0.1\lib\site-packages (from win10toast)
Requirement already satisfied: pywin32>=223 in c:\anacondapython2.5.0.1\lib\site-packages (from pypiwin32->win10toast)
Installing collected packages: win10toast
Successfully installed win10toast-0.9

C:\Windows\System32>dir D:\
 Volume in drive D has no label.
 Volume Serial Number is CAB3-B5BE

 Directory of D:\

13-02-2018  18:33    <DIR>          Installations
20-02-2018  14:45    <DIR>          ISSUES
13-02-2018  18:12    <DIR>          MATLAB
23-02-2018  14:58    <DIR>          projects
17-04-2017  17:48    <DIR>          Windows
               0 File(s)              0 bytes
               5 Dir(s)  98,658,492,416 bytes free

C:\Windows\System32>mkdir D:\Python2.7

C:\Windows\System32>cd D:\Python2.7 && D:

D:\Python2.7>dir
 Volume in drive D has no label.
 Volume Serial Number is CAB3-B5BE

 Directory of D:\Python2.7

05-03-2018  10:42    <DIR>          .
05-03-2018  10:42    <DIR>          ..
05-03-2018  10:17           183,001 Downloads-Black-Folder.ico
               1 File(s)        183,001 bytes
               2 Dir(s)  98,658,308,096 bytes free

D:\Python2.7>python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 15 2017, 03:34:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from win10toast import ToastNotifier
>>> import time
>>>
>>> toaster = ToastNotifier()
>>> toaster.show_toast("Hello Programmers!!!",
...                    "Python is really awesome, I am here for 10 seconds!",
...                    icon_path="Downloads-Black-Folder.ico",
...                    duration=10)
True
>>>
>>> toaster.show_toast("Good morning Dear",
...                    "How are you today?",
...                    icon_path=None,
...                    duration=5,
...                    threaded=True)
True
>>>
>>> # Wait for threaded notification to finish
... while toaster.notification_active():
...     time.sleep(0.1)
...
>>>
  1. Create any file named win10-toast-notifications.py inside D:\Python2.7 paste the above Python code and run using the below command
python win10-toast-notifications.py

You will see 2 notifications on your system.

That's it.

Also see

Setting up a cron job in Windows

How to schedule a Batch File to run automatically in Windows 10/8/7

@diamondbroplayz
Copy link

ty man dope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment