Re: Tkinter fonts setting

Discussion in 'Python' started by Gabriel Genellina, Feb 6, 2008.

  1. En Wed, 06 Feb 2008 14:02:35 -0200, Unnamed One <>
    escribi�:

    > jim-on-linux wrote:
    >> On Tuesday 05 February 2008 15:22, Unnamed
    >> One wrote:
    >>
    >>> First question - is it possible to set
    >>> font to default OS font for window text?
    >>> It would be preferable, while on my
    >>> Windows XP system Tkinter sets small
    >>> Helvetica-style font by default.
    >>>
    >>> Secondly, can I set font globally (or
    >>> specify "default" font for widgets)? In
    >>> fact, all I want is to get default OS font
    >>> unless (rarely) I need to specify another.

    >>
    >> Go to:
    >> http://www.pythonware.com/library/tkinter/introduction/
    >>
    >> Read chapter 6, Widget Styling, there is a
    >> section on Fonts which has a sub-section on
    >> System Fonts.


    None of them is suitable as a default text font. Prior to Tk 8.5, there is
    no way to get the "right" fonts used by the OS/desktop/theme. Tk 8.5 may
    provide that, but I haven't got it yet (see
    http://www.tcl.tk/cgi-bin/tct/tip/145.html)

    > Regarding my questions, I guess both are impossible in Tkinter (as I
    > didn't found anything about that in any Tkinter documentation), but
    > there still must be a way to get the default OS font name and size
    > (maybe outside of Tkinter), because it's always advised to use them in
    > applications.


    Yes. Your second question is easy; google for "tkinter default font".
    To obtain the desired font description, on Windows, you can use the
    pywin32 package or ctypes to call the following functions, and then
    configure Tkinter to use the desired font by default.
    Use SystemParametersInfo(SPI_GETNONCLIENTMETRICS,...) to obtain a
    NONCLIENTMETRICS structure.
    From it, obtain the lfMessageFont field (this is the default font for
    message boxes; you may be interested on others too, like lfMenuFont). It
    has all the info you need: lfFaceName is the font name, the various flags
    determine the font style, note that "bold" == lfWeight>=500.
    Maybe lfHeight it's a bit complicated; it's the height in pixels, to
    convert to points (1/72"):

    hdc = GetDC(0)
    dpi = GetDeviceCaps(hdc, LOGPIXELSY)
    font_size = int(round(abs(lfHeight) * 72 / dpi))
    ReleaseDC(0, hdc)


    --
    Gabriel Genellina
     
    Gabriel Genellina, Feb 6, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. import newbie

    Idiots guide to fonts with tKinter

    import newbie, Aug 4, 2005, in forum: Python
    Replies:
    2
    Views:
    759
    James Stroud
    Aug 5, 2005
  2. Unnamed One

    Tkinter fonts setting

    Unnamed One, Feb 5, 2008, in forum: Python
    Replies:
    0
    Views:
    420
    Unnamed One
    Feb 5, 2008
  3. Unnamed One

    Re: Tkinter fonts setting

    Unnamed One, Feb 6, 2008, in forum: Python
    Replies:
    0
    Views:
    877
    Unnamed One
    Feb 6, 2008
  4. sam
    Replies:
    0
    Views:
    445
  5. farzaneh

    setting fonts in ASP.NET

    farzaneh, Mar 26, 2012, in forum: .NET
    Replies:
    0
    Views:
    916
    farzaneh
    Mar 26, 2012
Loading...

Share This Page