Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

menu bar cut and paste

Status
Not open for further replies.

edwong

Programmer
Mar 26, 2003
30
US
Hi,
I created a menu as follows:

menubutton .b.mb -text File -menu .b.mb.menu -relief raised
pack .b.mb -side left -ipadx 2

set m [menu .b.mb.menu -tearoff 1]
$m add command -label cut -command { }
$m add command -label paste -command { }

what should i put inside command to make it work as cutting and pasting words in a entry label?

thx
 
Here is a piece of code.
Doesn't deal with words.
Code:
  pack [entry .e1]
  pack [entry .e2]
  pack [button .b1 -width 10 -text Cut -command cut]
  pack [button .b2 -width 10 -text Paste -command paste]
  focus -force .e1
  .e1 insert 0 "this is a string"
  .e1 selection range 8 end
  proc cut {}   {
    set first [.e1 index sel.first]
    set last [.e1 index sel.last]
    set selection [string range [.e1 get] $first $last]
    clipboard clear
    clipboard append $selection
    .e1 delete sel.first sel.last
  }
  proc paste {}   {
    focus -force .e2
    .e2 insert 0 [selection get -selection CLIPBOARD]
    .e2 selection range 0 end
  }
Try Cut, then Paste.
Try again.
The second time, there is no selection so
Code:
sel
is not defined.

HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top