2025, Dec 24 21:00
Tkinter Canvas PostScript export shows black rectangles on Windows 10 with Python 3.12 - fix by upgrading to Python 3.13
Troubleshooting Tkinter Canvas.postscript on Windows 10: embedded widgets become black rectangles in Python 3.12. Fix it by upgrading to Python 3.13 today.
Exporting a Tkinter Canvas to PostScript can be surprisingly platform- and version-sensitive. A specific case that bites on Windows 10 with Python 3.12 is that widgets embedded via create_window render as black rectangles in the .ps output, while the same code behaves correctly on Debian 12. Below is a minimal example that reproduces the behavior and a straightforward way to resolve it.
Repro case
The script embeds a Frame with a Label into a Canvas and draws a green oval around it, then saves the result to PostScript. On affected setups (Windows 10 + Python 3.12), the frame background appears, but child widgets turn into black rectangles in the generated outfile.ps.
from tkinter import Tk, Canvas, Frame, Label
class Showcase(Tk):
def __init__(self):
super().__init__()
board = Canvas(self)
board.config(background="white", width=120, height=120)
board.pack()
msg = "Hello Word!"
pane = Frame(board)
Label(pane, text=msg).pack(padx=2, pady=2)
center = (60, 60)
board.create_window(center, window=pane)
ring = (center[0]-40, center[1]-40, center[0]+50, center[1]+50)
board.create_oval(ring, width=3, outline="green")
self.update()
board.update()
self.update_idletasks()
left, top, right, bottom = board.bbox("all")
board.postscript(file="outfile.ps", colormode="color", x=left, y=top, width=right, height=bottom)
print("Wrote file outfile.ps...")
app = Showcase()
app.mainloop()What’s going on
On Windows 10 with Python 3.12, Canvas.postscript does not correctly capture the child widgets placed via create_window. Instead of rendering the Label and other embedded controls, it emits black rectangles. The same code works on Debian 12. In this scenario the background set by the frame passed to create_window shows up, but its children do not.
Resolution
Upgrading Python resolves the issue. Running the very same script under Python 3.13 produces the expected PostScript output on Windows 10. Python 3.13.3 was explicitly verified to work. No code changes are required beyond running the script on the newer interpreter.
Here is the same script, ready to run on Python 3.13+:
from tkinter import Tk, Canvas, Frame, Label
class Showcase(Tk):
def __init__(self):
super().__init__()
board = Canvas(self)
board.config(background="white", width=120, height=120)
board.pack()
msg = "Hello Word!"
pane = Frame(board)
Label(pane, text=msg).pack(padx=2, pady=2)
center = (60, 60)
board.create_window(center, window=pane)
ring = (center[0]-40, center[1]-40, center[0]+50, center[1]+50)
board.create_oval(ring, width=3, outline="green")
self.update()
board.update()
self.update_idletasks()
left, top, right, bottom = board.bbox("all")
board.postscript(file="outfile.ps", colormode="color", x=left, y=top, width=right, height=bottom)
print("Wrote file outfile.ps...")
app = Showcase()
app.mainloop()Why this matters
Cross-platform GUI exports are often part of reporting, printing, or archiving workflows. A script that works on Linux but degrades on Windows can quietly produce unusable assets. Knowing that the problem is tied to a specific runtime combination helps avoid misdiagnosing widget layout, Canvas logic, or rendering flags.
Takeaways
If you hit black rectangles when exporting a Tkinter Canvas containing embedded widgets on Windows 10 with Python 3.12, move to Python 3.13. Confirmed runs on Python 3.13.3 behave correctly, and no changes to your Tkinter code are necessary. When you rely on Canvas.postscript for deliverables, keep your runtime version consistent across environments and upgrade when you see platform-specific rendering discrepancies.