SkipHuffman has asked for the wisdom of the Perl Monks concerning the following question:

I am really confused by this. I need an interface with some fields read only (labels) and some editable (data). I cannot seem to prevent editablity. I have tried two things that I think should work, this:

$Cell[1] = { CellType => "ROText", Row => 0, Col => 0, Contents => "Bank\\Branch\\Dept:" }; $Cell[2] = { CellType => "ROText", Row => 1, Col => 0, Contents => "Requestor:" }; foreach (1 .. $#Cell) { if (${$Cell[$_]}{'CellType'} == "Text") { $cell = $grid->Text( -width => 17, -height => 1, )->grid( -row => ${$Cell[$_]}{'Row'}, -sticky => "nsew", -column => ${$Cell[$_]}{'Col'}, ); } elsif (${$Cell[$_]}{'CellType'} == "ROText") { $cell = $grid->ROText( -width => 17, -height => 1, )->grid( -row => ${$Cell[$_]}{'Row'}, -sticky => "nsew", -column => ${$Cell[$_]}{'Col'}, ); }; $cell->Contents("${$Cell[$_]}{'Contents'}"); };

And this:

foreach (1 .. $#Cell) { if (${$Cell[$_]}{'CellType'} == "Text") { $cell = $grid->Text( -width => 17, -height => 1, -state =>'normal', )->grid( -row => ${$Cell[$_]}{'Row'}, -column => ${$Cell[$_]}{'Col'}, ); } elsif (${$Cell[$_]}{'CellType'} == "ROText") { $cell = $grid->Text( -width => 17, -height => 1, -state =>'disabled', )->grid( -row => ${$Cell[$_]}{'Row'}, -column => ${$Cell[$_]}{'Col'}, ); }; $cell->Contents("${$Cell[$_]}{'Contents'}"); };

Both of these result in fields that can be clicked on and edited.

What am I doing wrong?

Skip

Replies are listed 'Best First'.
Re: Read Only fields from Tk, neither Text or ROText seem to work.
by rinceWind (Monsignor) on Oct 25, 2006 at 15:04 UTC

    Try using a Label rather than a Text (or a ROText).

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      Can I have multiple labels in a frame?

      Skip

        You can indeed. Whichever geometry manager you are using for the frame(grid, pack, whatever) will help you organise how these are laid out in the frame.

        --

        Oh Lord, won’t you burn me a Knoppix CD ?
        My friends all rate Windows, I must disagree.
        Your powers of persuasion will set them all free,
        So oh Lord, won’t you burn me a Knoppix CD ?
        (Missquoting Janis Joplin)

Re: Read Only fields from Tk, neither Text or ROText seem to work.
by swampyankee (Parson) on Oct 25, 2006 at 15:09 UTC

    One problem may be your use of == for string comparison. Try using eq. Both your strings numberify (that's a horrid non-word; forgive me) to 0.

    emc

    At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

    —Igor Sikorsky, reported in AOPA Pilot magazine February 2003.

      Thanks, I would have caught that slop eventually. But that is not going to cause this problem.

      Skip

        I probably would have approached it differently to start with, in that I would have used label and entry widgets, vs Text/ROText, mostly because everything in your sample seems to be single-line fields. On the other hand, I've no clue as to how many label/entry pairs you would need; at some number (a half-dozen? a score?), your method may be less unwieldly than using label/entry pairs.

        emc

        At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

        —Igor Sikorsky, reported in AOPA Pilot magazine February 2003.

      On second thought, that MAY have something to do with it.

      Third Thought! That was it! Weird results for what was going on. Thanks!

      Skip