[Tkinter-discuss] Canvas() to Image() fonts

Bob Greschke bob at greschke.com
Fri Jul 28 15:00:10 EDT 2023


Hi Michael!

I'm working up to Image.save("something.png"). The program will produce a picture for each of five different monitors each day, and then they'll end up on a web page, so a .png is desired. The program now draws the canvas, then uses an ImageGrab.grab() to make a picture of the Canvas. The problem, in Debian/X11/etc. is that you have to be logged in and looking at what is going on. If you try to run the image-making remotely (ssh -Y'ing), or using a cron job, everything works, but the pictures come out blank because there's no valid $DISPLAY. I'm trying to get it automated with the Image, however forcing me to look at the pictures and watch for anomalies in the signals each day is not a bad thing. :)

Yeah, getting the font of an Entry() field for the proportional font, or from a Text() for the mono-spaced font is just what I figured out 20+ years ago. It seemed to work on everything everywhere back then and kept all of the fonts consistent within a program on a given platform.

Bob
The picture collection is at www.passcal.nmt.edu/~bob/gpsmon

> On 2023-07-28, at 11:10, Michael Lange <klappnase at web.de> wrote:
> 
> Hi,
> 
> On Fri, 28 Jul 2023 09:08:11 -0600
> Bob Greschke <bob at passcal.nmt.edu> wrote:
> 
>> Hi!
>> 
>> I'm plotting some stuff to a Canvas() (second-by-second signal-to-noise
>> values for GPS satellites) and using something like
>> 
>> 
>> 
>> in the program to get the font to use for text labels and stuff on the
>> canvas.
>> 
>> I can't figure out how to get the same font for the an Image (so I can
>> duplicate the Canvas and save it as a png, of course). Without
>> specifying anything the text used on the image looks something like
>> Courier.
>> 
> 
> do you use Canvas.postscript() to export the canvas contents to an image?
> If yes, the problem is probably that Tk and postscript disagree about the
> exact spelling of the font name and so postscript falls back to some
> default font.
> 
> (As a side note:
> 
> PROGPropFont = Font(font = Entry()["font"])
> 
> seems a bit over-complicated to me, simply doing
> 
> PROGPropFont = Font(name = "TkDefaultFont", exists = True)
> 
> should give you the same result. scnr :) )
> 
> Have a nice day,
> 
> Michael
> 
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss
> 



More information about the Tkinter-discuss mailing list