From john at nmt.edu Thu Dec 6 23:07:35 2012 From: john at nmt.edu (John W. Shipman) Date: Thu, 6 Dec 2012 15:07:35 -0700 (MST) Subject: [Tkinter-discuss] Still don't understand ttk styling Message-ID: I've read and reread everything I can find about ttk, both in the Tcl docs and the Python 2.7 library docs, and I still have no idea how styling really works. Just to focus the discussion, here's a very simple task: change the font that appears on the tabs in the ttk.Notebook widget. The only way I found to do this is to change the root style's default like this: s = ttk.Style() s.configure('.', font=('Helvetica', 16, 'bold')) Is this the only way I can style the tab font? If not, can someone please explain how you figure out where Notebook gets its font, and how to change it? I've used all the methods of ttk.Style that one uses to explore the structure of a theme: .theme_names(), .element_names(), .element_options(), .lookup(), .configure(), and .layout(). All this tells me is that a Notebook has only one element, named Notebook.client. I understand that any option not configured in Notebook.client falls back to the "client" theme element. However, both those elements have only two attributes, 'background' and 'borderdwidth'. Nothing about a font attribute. Most grateful for any help that you might provide, I remain, John Shipman (john at 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 P.S. I'm well along on the ttk rewrite of our locally written Tkinter manual. The rest of what's left looks pretty straightforward, but I won't be happy with this version unless it can help people answer simple questions like the one posed here. The draft is here if you don't mind big chunks still missing: http://www.nmt.edu/tcc/help/pubs/tkinter85 Once it's done I'll move this version to the URL that is referenced several places around the web, which currently holds the 8.4, non-ttk version: http://www.nmt.edu/tcc/help/pubs/tkinter85 From klappnase at web.de Fri Dec 7 14:14:17 2012 From: klappnase at web.de (Michael Lange) Date: Fri, 7 Dec 2012 14:14:17 +0100 Subject: [Tkinter-discuss] Still don't understand ttk styling In-Reply-To: References: Message-ID: <20121207141417.2d8c2c52.klappnase@web.de> Hi John, On Thu, 6 Dec 2012 15:07:35 -0700 (MST) "John W. Shipman" wrote: > I've read and reread everything I can find about ttk, both in > the Tcl docs and the Python 2.7 library docs, and I still have > no idea how styling really works. > > Just to focus the discussion, here's a very simple task: change > the font that appears on the tabs in the ttk.Notebook widget. > > The only way I found to do this is to change the root style's > default like this: > > s = ttk.Style() > s.configure('.', font=('Helvetica', 16, 'bold')) > > Is this the only way I can style the tab font? If not, can > someone please explain how you figure out where Notebook > gets its font, and how to change it? I often find it hard to figure out thing like these, too. I think the best source is usually reading the .tcl files where widget and style defaults are defined. As far as I understand, ttk as well as standard tk uses the set of tk standard fonts by default, as returned by tkFont.names () , here: ('TkCaptionFont', 'font4143566764', 'TkSmallCaptionFont', 'TkTooltipFont', 'TkFixedFont', 'TkHeadingFont', 'TkMenuFont', 'TkIconFont', 'TkTextFont', 'TkDefaultFont') I don't have the tk source code at hand, I would guess these are hard-coded there, so that Text uses kTextFont and so on. It looks like ttk overrides these defaults in ttk/fonts.tcl first, then defines which font to use for styles in ttk/defaults.tcl , the relevant snippet here looks like: ttk::style configure "." \ -borderwidth 1 \ -background $colors(-frame) \ -foreground black \ -troughcolor $colors(-darker) \ -font TkDefaultFont \ (...) This may be overridden then by corresponding snippets in any theme definition. Now since there seems to be no font defined for notebook it apparently uses TkDefaultFont, so one method to change it might be to change TkDefaultFont with something like somewidget.tk.call('font', 'configure', 'TkDefaultFont', '-size', '28') Of course this changes the font for every other widget that uses TkDefaulFont either (which might be intentional when using themes otoh). If only the font on the ttk notebook tabs should be changed, one has to define a new font for the TNotebook.Tab resource, as in >>> s=ttk.Style() >>> s.configure('TNotebook.Tab') {'padding': '4 2', 'background': '#c3c3c3'} >>> s.configure('TNotebook.Tab', font=('courier', 18)) or >>> s.configure('TNotebook.Tab', font='TkTextFont') >>> s.configure('TNotebook.Tab') {'padding': '4 2', 'font': 'TkTextFont', 'background': '#c3c3c3'} This works, I am not sure if this is documented anywhere, though. This does also not seem to be coherent with other ttk widgets, in the ttk combobox for example the Listbox subwidget seems to share its defaults with any other listbox widget. Maybe this is because they consider the notebook tabs as something special, while e.g. the combobox is composed from "standard" widgets. To query the default notebook tab font one can do: >>> s=ttk.Style() >>> s.configure('TNotebook.Tab') {'padding': '4 2', 'background': '#c3c3c3'} >>> s.lookup('TNotebook.Tab', 'font') 'TkDefaultFont' >>> > I've used all the methods of ttk.Style that one uses to explore > the structure of a theme: .theme_names(), .element_names(), > .element_options(), .lookup(), .configure(), and .layout(). > All this tells me is that a Notebook has only one element, > named Notebook.client. I see, it looks somewhat like one just has to *know* about the 'TNotebook.Tab' style, which is anything but obvious when it is not documented. > P.S. I'm well along on the ttk rewrite of our locally written > Tkinter manual. The rest of what's left looks pretty > straightforward, but I won't be happy with this version unless it > can help people answer simple questions like the one posed here. > The draft is here if you don't mind big chunks still missing: > > http://www.nmt.edu/tcc/help/pubs/tkinter85 > Great work, I appreciate it really quite a lot! Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. A princess should not be afraid -- not with a brave knight to protect her. -- McCoy, "Shore Leave", stardate 3025.3 From john at nmt.edu Mon Dec 10 22:46:50 2012 From: john at nmt.edu (John W. Shipman) Date: Mon, 10 Dec 2012 14:46:50 -0700 (MST) Subject: [Tkinter-discuss] Tkinter 8.5 reference updated Message-ID: We are pleased to announce the completion of the rewrite of our Tkinter quick reference guide for version 8.5: http://www.nmt.edu/tcc/help/pubs/tkinter Improvements include: - Coverage of the ttk themed widgets. - A new section on setting up validation within Entry widgets. We welcome any and all comments and suggestions. Send them to: tcc-doc at nmt.edu Best regards, John Shipman (john at 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 From michael.odonnell at uam.es Tue Dec 11 08:38:34 2012 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 11 Dec 2012 08:38:34 +0100 Subject: [Tkinter-discuss] Tkinter 8.5 reference updated In-Reply-To: References: Message-ID: Thanks John, I have been using your older version as my main tkinter reference. Happy to see an update for tk8.5! Mick On Mon, Dec 10, 2012 at 10:46 PM, John W. Shipman wrote: > > We are pleased to announce the completion of the rewrite of our > Tkinter quick reference guide for version 8.5: > > http://www.nmt.edu/tcc/help/pubs/tkinter > > Improvements include: > > - Coverage of the ttk themed widgets. > > - A new section on setting up validation within Entry > widgets. > > We welcome any and all comments and suggestions. Send them to: > > tcc-doc at nmt.edu > > Best regards, > John Shipman (john at 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 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss -- Not sent from my iPhone