Change color on a widget from an inherited class? 
Author Message
 Change color on a widget from an inherited class?

        Hi all,

        I have inherited a class object called ScrolledListbox,  how is
        it possible to modify "Scrollbar::new ..." color?

======== This modified code is taken from Malcolm Beattie's tkperl package. =========
use Tk;

#--------------------------------------------------------------------------------------
$SB_BG = Green;
#^^^^^^^^^^^^^^   Added by me.
#--------------------------------------------------------------------------------------
{
    package ScrolledListbox;

    import Tk "tkpack";

    sub new {
        my($path) = shift;
        my($f) = Frame::new($path);

#--------------------------------------------------------------------------------------
        my($s) = Scrollbar::new($f, "-orient" => "vertical", "-background" => "$SB_BG",
#-----------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Comment : I added the above.  The above failed because $SB_FG is not expanded
#           by perl. (Why??)  Of course I can put the desired color directly in
#           the variable's ($SB_BG) place,  but then I can no longer change it.
#--------------------------------------------------------------------------------------
                                        "-slave" => $l, "-method" => "yview");
        $l->configure("-yscrollslave" => $s, "-yscrollmethod" => "set");
        tkpack($s, $l, "-side" => "left", "-fill" => "y", "-expand" => "y");
        bless {Scrollbar => $s, Listbox => $l, Default => $f};
    }

Quote:
}

$top = tkinit;
$sl = ScrolledListbox::new($top);
foreach (1 .. 25) {
    $sl->insert("end", "item" . $_);
Quote:
}

#--------------------------------------------------------------------------------------
$sl->configure("-background" => "$SB_BG");
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    Added by me.
#
# Comment: This line is added only after commenting out the above change in
#          the ScrolledListbox class, because I couldn't get the variable
#          ($SB_BG) to expand.  The above line only changes the listbox in
#          the class ScrolledListbox.  So now,  how do I setup the color for
#          the intended widget: Scrollbar ?
#--------------------------------------------------------------------------------------
tkpack $sl;
tkmainloop;

=======================================================================================

        Thanks in advance...

---
---------------------------_----------------------------------------------


4640 SW Macadam Ave.   | | | | |    VOICE: [USA] 1+503.228.1400 x251
Portland, OR 97201     | | | | |    FAX:   [USA] 1+503.228.0368
--------------------------------------------------------------------------



Sat, 15 Mar 1997 05:34:21 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. change background color on a widget when the textvariable changes

2. accessing class specific variables in inherited classes

3. Q: Changing Text-Color in Text-Widget?

4. Color Changes in Text widget

5. Change the color of the Scrolled-Widget

6. Text widget - change background color at insertcursor

7. Colors in Text widget and select colors

8. Letting background colors inherit/propogate to their children

9. inheriting Class Data

10. Help: using constants from inherited parent class

11. Multiple inheriting classes - clobbering - very strange problem

12. Perltoot - Inherited Class Design?

 

 
Powered by phpBB® Forum Software