[Tutor] Weird tkFont behavior
Steve Willoughby
steve at alchemy.com
Thu Jun 16 19:09:34 CEST 2011
On 16-Jun-11 09:52, Steve Willoughby wrote:
> I'm probably just doing something stupid, but I can't spot the error. I
> hope someone here can see what I'm looking past, or knows of a known
> issue with these widgets.
I think I solved it, actually.. as I was typing this up, I wondered in
passing about this:
> of the other fonts I configured for the other tags. Do I need to keep
> other references to the tkFont objects somewhere else or something?
and I think that was it. I recoded it so that I store the Font objects
independently of the tag configuration call, in case they were getting
destroyed accidentally somewhere (I know you have to do that with other
Tk objects such as images), and now I can't get the app to fail.
If interested, here's the new setup code:
| f=Tkinter.Text(self, ...)
|
| self.font_tags = {}
| for tag, weight, slant, others in (
| ('rm', tkFont.NORMAL, tkFont.ROMAN, {}),
| ('bf', tkFont.BOLD, tkFont.ROMAN, {}),
| ('it', tkFont.NORMAL, tkFont.ITALIC, {}),
| ('bi', tkFont.BOLD, tkFont.ITALIC, {}),
| ('ref',tkFont.NORMAL, tkFont.ITALIC, {'foreground':'blue',
'underline':True}),
| ):
| self.font_tags[tag] = tkFont.Font(family='Helvetica', size=10,
weight=weight, slant=slant)
| f.tag_config(tag, font=self.font_tags[tag], **others)
(Added "|" in the left column to hopefully get the text to indent right
with some mail readers. That's not part of the code, of course.)
--
Steve Willoughby / steve at alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
More information about the Tutor
mailing list