On rereading your post and responses, I think it probably is Tk::Entry that you're talking about.

There's a few tricky bits and gotchas when setting up -state => 'readonly'; and also when button presses result in writing to a readonly widget. So, here's some code to get you started.

#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow::->new(-title => "Ken's Guess"); my %frame_pack_opts = qw{-fill x -padx 10 -pady 10}; my $app_preamble_F = $mw->Frame()->pack(%frame_pack_opts); my $letter_buttons_F = $mw->Frame()->pack(%frame_pack_opts); my $copy_from_F = $mw->Frame()->pack(%frame_pack_opts); my $paste_to_F = $mw->Frame()->pack(%frame_pack_opts); my $exit_F = $mw->Frame()->pack(%frame_pack_opts); chomp(my $app_preamble = <<'EOT'); The "Copy from:" entry can only be modified with the "Select:" buttons. Any text here may be selected and copied. The "Paste to:" entry can be modified in any way you want. It's primary function was to test that text copied from the "Copy from:" entry could be pasted; however, you can also type text from the keyboard, select existing text, and delete text. EOT $app_preamble_F->Label(-text => $app_preamble, -justify => 'left' )->pack(-side => 'left'); my $copy_from_entry; my $copy_from_value = ''; $letter_buttons_F->Label(-text => 'Select: ')->pack(-side => 'left'); for my $letter ('A' .. 'G') { $letter_buttons_F->Button(-text => $letter, -command => sub { $copy_from_entry->configure(-state => 'normal'); $copy_from_value = $letter; $copy_from_entry->configure(-state => 'readonly'); } )->pack(-side => 'left'); } $copy_from_F->Label(-text => 'Copy from: ')->pack(-side => 'left'); $copy_from_entry = $copy_from_F->Entry( -textvariable => \$copy_from_value, -state => 'readonly' )->pack(-side => 'left'); chomp(my $paste_to_preamble = <<'EOT'); I have to assume that the widget, where you want to paste this text, is part of another application. Otherwise, this makes no sense at all. EOT $paste_to_F->Label(-text => $paste_to_preamble, -justify => 'left' )->pack(-anchor => 'w', -pady => 5); $paste_to_F->Label(-text => 'Paste to: ')->pack(-side => 'left'); $paste_to_F->Entry()->pack(-side => 'left'); $exit_F->Button(-text => 'Exit', -command => sub { exit; })->pack(); MainLoop;

This code represents a complete, working GUI. I suggest running it and understanding how it works; then make a copy and adapt that for your needs.

I'm still somewhat mystified with regards to what your ultimate goal might be. Have a read of "XY Problem" and ask yourself if that might apply here.

— Ken


In reply to Re: Disabling the keyboard inputs in Entry/Text widget [Tk GUI Code] by kcott
in thread Disabling the keyboard inputs in Entry/Text widget by KishKishore

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.