icon_path isn't working in win10toast module in python

折月煮酒 提交于 2021-01-07 02:17:14

问题


I'm attempting a countdown clock in python 3.7 using win10toast, time and playsound. Here's the code:

import time
import playsound
import win10toast

Toaster = win10toast.ToastNotifier()

def countdown(y):
    while y > 0:
        print(y)
        y -= 1
        time.sleep(1)
    playsound.playsound('alarm-clock-ringing.mp3')
    Toaster.show_toast('Countdown notifier', 'countdown over', duration=9,
                       icon_path=r'D:\img.ico')


try:
    x = int(input('how many seconds do you want to countdown?: '))
    countdown(x)

except ValueError:
    print('That wasn\'t an integer! Please enter an integer!')

It works fine, except for icon_path in line 14. The error I'm getting is:

ERROR:root:Some trouble with the icon (D:\img.ico): (0, 'LoadImage', 'No error message is available')

By the way, I'm using windows 10 pro 64-bit.

Thank you!


回答1:


Hello!

import time
from win10toast import ToastNotifier
toaster = ToastNotifier()
toaster.show_toast("Hello World!!!","Python is 10 seconds awsm!",icon_path= 
filename.ico,duration=10,threaded=False)
while toaster.notification_active():
          time.sleep(0.1)

Copy and Paste, Your Welcome :)




回答2:


Try using a .ico file, that would probably work..




回答3:


First, convert the .jpg or .png file that u have into a .ico file. U can do it using python's PIL library like this:

from PIL import Image
filename = "logo.png"
img = Image.open(filename)
img.save('logo.ico')

Now, u have saved the logo as an ico file, so u can easily use it in ur code like this:

from win10toast import ToastNotifier

toast = ToastNotifier()

file_name = 'logo.ico'

toast.show_toast("Notification","Notification Body", duration=5, icon_path = file_name)

Hope that this helps!



来源:https://stackoverflow.com/questions/62621139/icon-path-isnt-working-in-win10toast-module-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!