[Tutor] How to get a Tkinter window to print a color copy of itself as a .pdf file?

boB Stepp robertvstepp at gmail.com
Wed Apr 15 15:37:35 CEST 2015


On Wed, Apr 15, 2015 at 8:29 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, Apr 15, 2015 at 07:55:28AM -0500, boB Stepp wrote:
>> Solaris 10, Python 2.4.4
>>
>> I have very little experience with issuing print commands using a Unix
>> environment. Despite this, I wish to design a Tkinter window with a
>> "Print" button, which, when clicked, would create a copy of the
>> contents of the window as a .pdf file. GhostScript is available on my
>> systems.
>>
>> I know that the Canvas container has the ability to print itself to a
>> postscript file, but I do not want to use Canvas as my container
>> object.
>
> You will excuse me, I hope, but I'm afraid that comes across as rather
> foolish:
>
> "I want to hammer this nail into this piece of wood. I have a hammer,
> but I don't want to use a hammer. I would prefer to use a saw, or
> perhaps a paint brush. How can I do this?"
>
>
> Why don't you want to use a Canvas? That sounds like it will solve your
> problem. Use a Canvas as the container, give it a button, and have the
> button send a message to the Canvas saying "Print yourself to PDF
> file!"
>
> If you explain why you don't wish to use a Canvas, perhaps we can
> suggest a solution that doesn't involve trying to hammer nails with
> paint brushes.

Perhaps I am being foolish! But I do have my reasons, which, in this
case, is I wanted to take advantage of the pack and grid geometry
managers. These two tools seem to make the positioning of the widgets
much easier. Unless I am missing something, in a Canvas container I
will have to assign pixel coordinates for everything, which sounds
like a lot more work!

In any event, I *would* like to know how to solve the original
problem, creating a print button that will print the contents of its
overall container object.



-- 
boB


More information about the Tutor mailing list