So, I'm coding a IDE in Python and I'm using Tkinter for the GUI. What I'm looking for is a way to add a "recent files" menu to the menu that opens when you right click the program's icon in Windows's task bar. I have a picture to show what I'm looking for:

Screen capture

Yeah, I want to add a "Recent Files" menu ("Viimeksi käytetyt tiedostot" in finnish) to my program.
Some of the texts are in finnish but I hope you get the idea... xD

I think that you can do this in Python & Tkinter, because IDLE (the program where the screenie is from) is coded in Python & Tkinter. I tried to look in to IDLE's source but I wasn't able to find anything usefull.

Thanks for already,

-Tyyppi_77

Dani AI

Generated

This is implemented by Windows "Jump Lists" (the menu shown when you right‑click a taskbar button). To get a per‑app "Recent files" list you have two practical options: (A) give your process a unique AppUserModelID and add opened files to the shell Recent list (Windows will show those as the Recent category), or (B) build a custom Jump List (ICustomDestinationList + IShellLink) to supply categories and tasks yourself. (learn.microsoft.com)

Quick, reliable approach (works from Python):

  1. Call SetCurrentProcessExplicitAppUserModelID early at startup so Windows groups your windows separately from pythonw.exe (this addresses @TrustyTony's observation). 2) When a file is opened, call SHAddToRecentDocs to add it to Recent. The pywin32 shell module exposes SHAddToRecentDocs. Example:
# call this at startup, before creating any UI
import ctypes
from ctypes import wintypes
from win32com.shell import shell

SetAppID = ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID
SetAppID.argtypes = [ctypes.c_wchar_p]
SetAppID.restype = wintypes.HRESULT
SetAppID("MyCompany.MyIDE")   # choose a unique ID (no spaces, <=128 chars)

# when opening a file
shell.SHAddToRecentDocs(shell.SHARD_PATHW, r"C:\path\to\file.txt")

SetCurrentProcessExplicitAppUserModelID must run before any UI or SHAddToRecentDocs calls. SHAddToRecentDocs adds entries that Windows will surface in the Recent category; custom categories or tasks require the Taskbar COM interfaces (ICustomDestinationList / IShellLink) and are more involved to implement from Python (use comtypes or pywin32 COM). Also be aware that user privacy settings and group policy can suppress Recent/Frequent data. (learn.microsoft.com)

Recommended Answers

All 3 Replies

I think the list contains all programs run by pythonw.exe (probably python.exe has separate list), idle is one of them. The list is propably not files edited with idle.py (I can not check it from work computer).

Okay, thanks for the reply! I guess I'll just put the menu to the menubar then.

Is there a way to do this with pywin32?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.