Notifier = nManager.create_toast_notifier(path)Īctivated_token = notification. You can use buttons in winrt like this: import .notifications as notifications Print("We can still do things while the notification is displayed") Thread = threading.Thread(target=lambda: time.sleep(duration)) # If we don't, the program will just continue and maybe even end before a button is clicked # We have to wait for the results from the notification If you don't install the MSI first, toasts will not appear. Installing via the MSI creates the Start menu shortcut with the AUMID and COM CLSID so your notifications can appear and be actionable. Notifier = nManager.create_toast_notifier(sys.executable)ĭuration = 7 # "short" duration for Toast notifications Launch the Desktop Toasts app from the Start menu After you've installed with the MSI once, you can debug straight from Visual Studio. #link it to your Python executable (or whatever you want I guess?) Notification.add_activated(handle_activated) Notification = notifications.ToastNotification(xDoc) Subprocess.Popen('explorer ""'.format(path)) As a useful example, the following code (Python 3.9) will open your "Documents" folder in a Windows Explorer window using subprocess call in the handle_activated function. I've written out more details over here, but I'll provide just the code from that for those that just want a solution. I started from the other WinRT answer here but that one has errors and is missing critical steps. I don't have enough rep to just comment a link to my other answer.but I've found a solution using WinRT that displays buttons that are usable from within your Python code (unlike the answer that only provides a "dismiss" option). To do this, do the following as your appropriate: If you are running Windows 10, Windows 8.1 or Windows 8, first run the inbox Deployment Image Servicing and Management (DISM) tool prior to running the System File Checker. Once an action is selected, the arguments are sent to the application To do this, follow these steps: Open an elevated command prompt. The Toast Content article explains how the content is created, either through code or XML. Notifier.show(notifications.ToastNotification(xDoc)) Notifier = nManager.create_toast_notifier() NManager = notifications.ToastNotificationManager Then uses it with surprisingly little code: The linked answer explains how to install Python/WinRT with : pip install winrt I won't vote to close as duplicate, because the upvoted answers to that question all work with notifications, not toasts. Luckily, someone wrote a real answer recently, using the Python/WinRT package. To display a toast, one has to use WinRT. A Toast's content is specified using XML and can contain buttons, formatting, images etc. Unfortunately, win10toast cheats and displays old-style, Windows XP notifications, not toasts.
0 Comments
Leave a Reply. |