0
votes

I'm trying to use the TCL command to capture the name and path from a file into the clipboard. I realized that it works only for general text instead for file.

Thanks, Felipe

This is my TCL Example:

    set keysym "Copy Activated"
    pack [label .l -textvariable keysym -padx 2m -pady 1m]
    set function {}
    bind . <Key> {
    set var "%K"
    lappend function $var
     if { [ lindex $function end-1 ] == "Control_L" || [ lindex $function end ]   == "c"  } { set contents [clipboard get] }
     if { [ lindex $function end-1 ] == "Control_L" || [ lindex $function end ] == "v"  } { eval clipboard clear; clipboard append $contents}   
    }
1

1 Answers

0
votes

That's probably more complicated than it needs to be. Try something like this:

pack [label .foo -textvariable myVar]
bind . <Control-v> {set myVar [clipboard get]}
bind . <Control-c> {clipboard clear ; clipboard append $myVar}
set myVar foobar

I've changed the sense of Control-C and Control-V around since it's more conventional to copy from the clipboard on Control-V and to the clipboard on Control-C.

This code probably doesn't do what you wanted, but it's a bit unclear (to me at least) what it is you want to do. A file name and path can most certainly be copied through the clipboard. Does the above code give you any ideas how to solve it? If not, it would be easier to help if you clarified your problem a bit.

Updated answer after comment

If you mean a text widget you can already paste anything you have in the clipboard with Control-V, that binding is standard. Tcl can't help you with Explorer functionality, but if you Shift-rightclick on the file you should get the option "Copy as Path" which does what you want (at least in Windows 7 and later). Note that the path is copied with attached double quotes (as in "C:\foo\bar\baz.txt"); you might want to trim those off.