On Mon, Apr 27, 2009 at 12:15 PM, Sorin Schwimmer <sx...@yahoo.com> wrote:
>
> Hi All,
>
> I installed recently tcl/tk 8.5.6, Python 2.6.2 and pyttk 0.3 on a Linux 
> (Gentoo) machine.
>

Hi Sorin, thanks for giving ttk a try.

> I would like to be able to change two things in entries:
> - the font should be the default, but in italics
> - selected text in an entry should have white background and gray foreground
>
> How can I accomplish that? How can I determine what is the actual 
> TkDefaultFont?
>

I will answer in the reverse order.

The easier way to know what defines the actual TkDefaultFont is to use
the tkFont module (it is included with tkinter):

import Tkinter
import tkFont
Tkinter.Tk()
print tkFont.Font(font='TkDefaultFont').configure()

Now, to change the selection colors in a ttk.Entry, simply do:

import ttk
style = ttk.Style()
style.map('TEntry', selectbackground=[('!disabled', 'white')],
selectforeground=[('!disabled', 'grey')])

And to change the ttk.Entry font to italics you don't use themes
actually. There is an option named 'font' for this widget, so you just
have to change it. Follows the correct way to do what you are after:

import ttk
import tkFont

entry = ttk.Entry()
myfont = tkFont.Font(font=str(entry['font']))
myfont['slant'] = 'italic'
entry['font'] = myfont
entry.pack()

> Thanks
> SxN

Regards,

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

Reply via email to