Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62143

Re: Determining whether a glyph is available in Tkinter

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Determining whether a glyph is available in Tkinter
Date 2013-12-16 22:58 -0500
References <f84fbcb9-e784-4a2a-9c27-d55136e3c7b2@googlegroups.com> <mailman.4233.1387222873.18130.python-list@python.org> <c2a0c7e1-4983-4187-b35f-8f7c0ae834e5@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4255.1387252699.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/16/2013 6:59 PM, wmcbrine@gmail.com wrote:
> I'm not going to control the font.

Tk widgets that display text must use *some* font. If you do not select 
one, then you get the system-dependent default.
for k, v in tk.Text().configure().items(): print(k, v)
...

font ('font', 'font', 'Font', <font object: 'TkFixedFont'>, 'TkFixedFont')

TkTextFont may be preferable for your purposes, although on Windows both 
might be Courier New.

> This is for a program that's
> distributed to the general public, for use on a wide variety of
> systems. But what I do in the current version is to use the ASCII
> label strings by default, and have a command-line option to select
> the "graphical" (non-ASCII Unicode) labels. What I want is to make
> the graphical labels the default, and have the program detect, at
> runtime, whether any of the glyphs used in the fancy labels would
> render as "\uNNNN" in whatever the default font for the buttons is,
> and automatically revert to the ASCII labels in that case.

I would not assume that the default covers more than ascii.

But to answer your question, this might work: fonts have a measure() 
method that returns what the pixel length of a string would be if it 
were to be displayed.

 >>> import tkinter.font as tkf
 >>> ft=tkf.Font(font='TkFixedFont')
 >>> ft.metrics()
{'ascent': 17, 'descent': 5, 'fixed': 1, 'linespace': 22}
 >>> ft.measure('a')
12
 >>> ft.measure('\u9fff')
12

*If* the measure is, say, 50 or more for a character that would display 
as \uNNNN, then you would know. Go ahead and experiment.

> I'm assuming this is possible, because Tkinter itself seems to know
> which glyphs are unavailable, or they'd probably be showing up as
> those boxed number characters or question marks instead of "\uNNNN".

I do not know whether it is tk itself or a system graphics call that 
translates a sequence of codes to pixels on the screen.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Determining whether a glyph is available in Tkinter wmcbrine@gmail.com - 2013-12-16 09:32 -0800
  Re: Determining whether a glyph is available in Tkinter Terry Reedy <tjreedy@udel.edu> - 2013-12-16 14:41 -0500
    Re: Determining whether a glyph is available in Tkinter wmcbrine@gmail.com - 2013-12-16 15:59 -0800
      Re: Determining whether a glyph is available in Tkinter Terry Reedy <tjreedy@udel.edu> - 2013-12-16 22:58 -0500
        Re: Determining whether a glyph is available in Tkinter wmcbrine@gmail.com - 2013-12-19 15:10 -0800
          Re: Determining whether a glyph is available in Tkinter wxjmfauth@gmail.com - 2013-12-20 01:18 -0800

csiph-web