-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ttk::treeview ttkStyleConfigure #8
Comments
Hi Kelly, your example code looks nearly complete. By default the I would refer to "Styling Options" section in https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_treeview.htm#M5. To configure all treeview widgets without a set use warnings;
use strict;
use Tcl::pTk;
my $mw = MainWindow->new();
my $int = $mw->interp;
my $tree = $mw->Scrolled('ttkTreeview',-columns => [qw/ id token/], -show => 'headings', -scrollbars => 'se' )->pack(-fill => 'both', -expand => 1);
$tree -> tagConfigure('title', -background=>'red');
$tree -> tagConfigure('oddrow', -background=>'white');
$tree -> tagConfigure('evenrow', -background=>'yellow');
#my $style = $tree->cget(-style);
my $style = 'Treeview';
my $font = $tree->ttkStyleLookup( $style, -font);
$mw->ttkStyleConfigure($style, -background=>'sky blue', -fieldbackground => 'sea green');
$mw->ttkStyleConfigure('Heading', -background=>'light salmon');
## Code to insert the data nicely
foreach my $col (qw/ id token/){
my $name = uc($col);
$tree->heading($col, -command => [\&SortBy, $tree->Subwidget('scrolled'), $col, 0], -text => $name);
my $len = $tree->fontMeasure($font, $name);
$tree->column($col, -width, $len+110);
}
$tree->insert('', 'end', -values => ['1234', '5678'], -tags => 'oddrow');
$tree->insert('', 'end', -values => ['abcd', 'efgh'], -tags => 'evenrow');
$tree->insert('', 'end', -values => ['!@#$', '%^&*'],); # An item without a tag
my $but = $mw->ttkButton(
-text => "Close",
-command => sub {
$mw->destroy;
}
)->pack();
$int->MainLoop;
sub SortBy{
} (In GitHub markdown you can use ```perl … ``` to get Perl syntax highlighting) For Also be aware there was an issue with Does this help? |
Hi Christopher, this helps a lot to understand the 'bridge' between Tcl and Tcl::pTk. However, I ran your adapted script on Windows 10, Tk 8.6.10, Tcl::pTk 1.08. I get the following: On macOS (Mojave) also Tk 8.6.10, Tcl::pTk 1.08, I get the following: Is it possible that the behavior is different based on the OS (for example it seems that on macOS the headings get their own style). I am pretty sure Tcl is linking the right Tk (1.08). Having several Tcl/Tk installations, I had in the past some problems with this, but my tests say the script is run against the right (latest) installation. Any idea? |
The first screenshot is indeed what I saw for the 'vista' and 'xpnative' Ttk themes. I hadn't tried the script on Aqua, but doing so now I do see similar issues with settings not being observed correctly for various Ttk themes (for example the header uses the Treeview Keep in mind that if either of the foreground or background colors is manually set, the other should be manually set as well. Otherwise, dark mode/high contrast mode/etc. might use automatic colors which are difficult to see next to the manually-set ones. I have also encountered difficulty getting Tcl.pm to use the correct Tcl/Tk installation on occasion, so that is something else I want to look into improving. |
The upstream reports I opened are likely to be closed as "won't fix". Tcl/Tk developers' response so far is that Ttk widgets (including ttk::treeview) emphasize having appearance which is consistent with platform style, and so themes may intentionally not support customization. One suggests using another table-like widget (e.g. Tablelist or TreeCtrl) if customizations are desired. |
Is it possible to configure the style of the treeview from within Tcl::pTk? In particular, I am trying to configure the header. Since I am missing any syntax example for that, I just started with configuring the entire widget. In the example below, I simply try to change the background of the entire treeview, but it seems that ttkStyleConfigure (documented in Tcl::pTk::Tile) does not produce any effect.
Also any idea on how to configure the header?
The text was updated successfully, but these errors were encountered: