Below my signature is a trivial ttk script with two widgets: an
Entry and a quit button.  Styling the font on the quit button
works great.  But styling the font on the Entry widget does not;
I always get the default font, which is a bit small for many
people over the age of 40.

I've tried a number of things, but either I'm missing something
really stupid in my code, or there is a defect in the ttk.Entry
code that it does not pick up a font.

Here's our version:

tk.__version__
'$Revision: 81008 $'
ttk.__version__
'0.3.1'

I would appreciate any suggestions.

Best regards,
John Shipman (j...@nmt.edu), Applications Specialist
New Mexico Tech Computer Center, Speare 146, Socorro, NM 87801
(575) 835-5735, http://www.nmt.edu/~john
  ``Let's go outside and commiserate with nature.''  --Dave Farber
================================================================
#!/usr/bin/env python
# wtfentry: Why can't I specify a font on a ttk.Entry?
# Submitted by John W. Shipman, j...@nmt.edu

import sys
import ttk
import Tkinter as tk
import tkFont

class App(ttk.Frame):
    def __init__(self):
        ttk.Frame.__init__(self, None)
        self.grid()
        self._styling()
        self._createWidgets()

    def _styling(self):
        self._mainFont = tkFont.Font(family='Helvetica', size=20,
                                     slant='italic')
        self._entryFont = tkFont.Font(family='Helvetica', size=36)

        self._entryStyle = ttk.Style()
        self._entryStyle.configure('My.TEntry', font=self._entryFont)

        self._buttonStyle = ttk.Style()
        self._buttonStyle.configure('My.TButton', font=self._mainFont)

    def _createWidgets(self):
        self._entryVar = tk.StringVar()
        self._entryVar.set('initial value')
        self._entry = ttk.Entry(self,
            style='My.TEntry', textvariable=self._entryVar)
        self._entry.grid()

        self._quitButton = ttk.Button(self, text='Quit',
            style='My.TButton', command=self.quit)
        self._quitButton.grid()

app = App()
app.mainloop()


_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to