1

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 ?

10
  • Try this Label(window, text=text, bg='black',fg='red').pack(padx=2, pady=2) Commented May 7 at 3:00
  • Still the same result : black rectangle and ne text in the output... Commented May 7 at 6:29
  • Use create_text() instead of create_window() if you just want to show text. Commented May 7 at 8:02
  • Try putting the label widget directly using create_window() instead (i.e. without the frame widget). Commented May 7 at 8:39
  • It does work when directly putting the Label in create_window(), however in my usecase I have a much more complicated Frame with different Widgets that I need to export to ps. Commented May 7 at 9:26

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.