Tk Source Code

View Ticket
Login
Ticket UUID: 2782346
Title: ttk::notebook configure styles for each tab
Type: RFE Version: None
Submitter: nobody Created on: 2009-04-27 18:19:21
Subsystem: 88. Themed Tk Assigned To: jenglish
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2020-01-03 18:02:19
Resolution: None Closed By: nobody
    Closed on:
Description:
It would be nice if one could specify a style for each tab in ttk::notebook instead of the default TNotebook.Tab. This would allow to add tab scrolling at script level, create tabs with different buttons (for example, like firefox tabs)
User Comments: bll added on 2020-01-03 18:02:19:
Attached a possible implementation that places the arrows in notebook tabs
and uses a -maxtabs option.

I originally wanted to put the arrows as images within the notebook tabs,
but the inability to access the 'user1' and 'user2' states prevents that
method.

The wiki has implementations where the arrows are 'placed' within the notebook
itself, but that look and feel of those are not always good.

fvogel added on 2020-01-03 08:39:49:

Brad Lanam wrote a script demonstrating scrolling notebook tabs here:

https://groups.google.com/d/msg/comp.lang.tcl/wJMIc_VRbro/2XomSqjSDAAJ

(Brad, coudl you perhaps post it in the present ticket as well, my newsreader awfully splits your lines up - Thanks!)


bll added on 2020-01-02 21:31:49:
A notebook tab has a 'state' command that can set normal, disabled, hidden.

But for a tab, there does not appear to be a way to access the ttk states, 
even though they exist (hover, selected, user1, et.al.).

This limits the ability to turn any tab elements on or off.

This rules out the method of creating arrow images within the tab itself.

bll added on 2020-01-02 18:10:17:
I think this is possible to code using the current tools.

It's a common request, though I do not see any complete 
implementations available on the wiki.

For purposes of the RFE, adding the 'user1' state to the first
displayed tab and adding 'user2' state to the last displayed
tab would make the coding easier. (user? states have already
been subverted to be system states in other widgets).

bll added on 2020-01-02 17:46:49:
Note that it is possible to change an element's image based 
on the current notebook tab state.  However, for the RFE, I
believe a "first" and "last" tab state would be necessary,
indicating the first tab displayed and the last tab displayed.

It may be possible to use the 'user1' (2, 3) states to code
this.  (I know nothing about how too many tabs act in a notebook).

      ttk::style element create \
         ${pfx}${theme}.Notebook.indicator image \
         [list $images(${pfx}tabindnotactive) \
         {hover active !selected !disabled} $images(${pfx}tabindhover) \
         {selected !disabled} $images(${pfx}tabindselected) \
         {disabled} $images(${pfx}tabinddisabled)]

fvogel added on 2020-01-02 10:31:37:

One could think at doing this the following way:

package require Tk
pack [::ttk::notebook .n] -fill both -expand true
set redcross [image create photo -format gif -data {R0lGODlhBwAHAIABAP8AAP///
        yH5BAEKAAEALAAAAAAHAAcAAAIMBIKmsWrIXnLxuDMLADs=}]
foreach tabs {Edit Check Close} {
    ::ttk::entry .n.[string tolower $tabs]
    .n add .n.[string tolower $tabs] -text $tabs -image $redcross
}
ttk::style configure TNotebook.Tab -compound left

# create a new style derived from TNotebook.Tab
ttk::style configure mystyle.TNotebook.Tab -compound right

# apply this new style to tab number 1 (doesn't work: unknown option "-style")
.n tab 1 -style mystyle.TNotebook.Tab

But this fails because -style is not a known option for a notebook tab. The -style option applies to widgets, not to tabs.

As a workaround one can always configure each tab directly through .n tab $id -option value... (instead of styling them).


Attachments: