pythontkintertkinter-canvas

Tkinter Canvas postscript outputing black rectangles instead of child widget


I am working on Tkinter (Python3.12) on Windows 10. My issue is that when using postscript on a Canvas on which a window was drawn, only black rectangles appear instead.

After some tests, the background of the frame given in the create_window method does appear, but there are black rectangles instead of the children widgets.

For a simple reproductible example, I ran the code from this question : Tkinter Canvas Postscript not capturing Window elements outside of screen frame both on Windows 10 and on Debian 12.

Here is a simplified code snippet which saves the canvas in outfile.ps :

from tkinter import Tk, Canvas, Frame, Text, Label

class Example(Tk):

    def __init__(self):
        """Example canvas with a circle and a frame and label"""
        super().__init__()
        cv = Canvas(self)
        cv.config(background="white", width=120, height=120)
        cv.pack()

        text = "Hello Word!"
        window = Frame(cv)
        Label(window, text=text).pack(padx=2, pady=2)
        pos = (60, 60)
        cv.create_window(pos, window=window)
        bbox = (pos[0]-40, pos[1]-40, pos[0]+50, pos[1]+50)
        cv.create_oval(bbox, width=3, outline="green")

        self.update()
        cv.update()
        self.update_idletasks()
        x1, y1, x2, y2 = cv.bbox("all")
        cv.postscript(file="outfile.ps", colormode="color", x=x1, y=y1, width=x2, height=y2)
        print("Wrote file outfile.ps...")


root = Example()
root.mainloop()

Running this on Windows gives the following image : link here, but it works on Debian 12.

Is this a Windows issue with no workaround ?


Solution

  • Upgrading to Python 3.13 solved the issue, so the explanation is probably a version incompatibility with Windows 10 and Python 3.12 for this particular case.