Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello jsteng and welcome to the monastery and to the wonderful world of perl!

I tried a bit and it seems i get trouble first time I query one property: $lb->itemcget($sel, '-background') so I provide the initial value manually: my $current_color_bg = $lb->itemcget($sel, '-background') || 'yellow';

Here a working example flipping the colors:

use strict; use warnings; use Tk; my $mw = MainWindow->new; my %next_color=(red=>'yellow',yellow=>'red'); my $lb = $mw->Scrolled( "Listbox", -bg => 'yellow', -fg => 'red', -scrollbars => 'e', )->pack; $lb->insert('end', "Item1", "Item2", "Item3"); $lb->bind( '<Double-1>', sub{ my $sel = $lb->curselection()->[0]; print "pressed $sel\n"; my $current_color_bg = $lb->itemcget($sel, '-background') || ' +yellow'; my $current_color_fg = $lb->itemcget($sel, '-foreground') || ' +red'; print "current color of the element $sel is $current_color_bg +on $current_color_fg\n"; $lb->itemconfigure( $sel, -background=> $next_color{$current_color_b +g}, -fg=>$next_color{$current_color_fg} ); } ); MainLoop;

Double clicking the first entry 3 time and one time the second:

pressed 0 current color of the element 0 is yellow on red pressed 0 current color of the element 0 is red on yellow pressed 0 current color of the element 0 is yellow on red pressed 1 current color of the element 1 is yellow on red

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: How to get foreground color from a TK::Listbox by Discipulus
in thread How to get foreground color from a TK::Listbox by jsteng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found