From bob at passcal.nmt.edu Fri Jul 28 11:08:11 2023 From: bob at passcal.nmt.edu (Bob Greschke) Date: Fri, 28 Jul 2023 09:08:11 -0600 Subject: [Tkinter-discuss] Canvas() to Image() fonts Message-ID: Hi! I'm plotting some stuff to a Canvas() (second-by-second signal-to-noise values for GPS satellites) and using something like PROGPropFont = Font(font = Entry()["font"]) 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. Thanks! Bob A little program info is at www.greschke.com/passcal/software/gpsview.html From klappnase at web.de Fri Jul 28 13:10:37 2023 From: klappnase at web.de (Michael Lange) Date: Fri, 28 Jul 2023 19:10:37 +0200 Subject: [Tkinter-discuss] Canvas() to Image() fonts In-Reply-To: References: Message-ID: <20230728191037.5c3c2265fafd339a7b58c2af@web.de> Hi, On Fri, 28 Jul 2023 09:08:11 -0600 Bob Greschke 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 From bob at greschke.com Fri Jul 28 15:00:10 2023 From: bob at greschke.com (Bob Greschke) Date: Fri, 28 Jul 2023 13:00:10 -0600 Subject: [Tkinter-discuss] Canvas() to Image() fonts In-Reply-To: <20230728191037.5c3c2265fafd339a7b58c2af@web.de> References: <20230728191037.5c3c2265fafd339a7b58c2af@web.de> Message-ID: <15F4E26F-22C3-4497-B25F-3A6E9B3408BE@greschke.com> 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 wrote: > > Hi, > > On Fri, 28 Jul 2023 09:08:11 -0600 > Bob Greschke 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 > From klappnase at web.de Sat Jul 29 16:52:17 2023 From: klappnase at web.de (Michael Lange) Date: Sat, 29 Jul 2023 22:52:17 +0200 Subject: [Tkinter-discuss] Canvas() to Image() fonts In-Reply-To: <15F4E26F-22C3-4497-B25F-3A6E9B3408BE@greschke.com> References: <20230728191037.5c3c2265fafd339a7b58c2af@web.de> <15F4E26F-22C3-4497-B25F-3A6E9B3408BE@greschke.com> Message-ID: <20230729225217.e3080fc78f343d66dc403178@web.de> Hi Bob, On Fri, 28 Jul 2023 13:00:10 -0600 Bob Greschke wrote: > 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. :) maybe you could use Canvas.postscript() and then convert the output to png with psconvert, not sure if this helps with the missing $DISPLAY though. Plus you might need to stick with a font whose spelling Tk and postscript agree about (I think Arial would be my first guess here). Have a nice day, Michael