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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

right mouse click 1

Status
Not open for further replies.

stewang

Programmer
Aug 21, 2003
77
0
0
NZ
Hello all:
I want to have a right mouse click when I click on a dialog box, but I don't known why my code can not work.
Would anyone help me, please.

Thanks
rgds
stewang


Code:
proc openFile {} {
	# use the built in file selection dialog
	set filename [tk_getOpenFile]
         bind filename <Button-3> { popUpLabel }
	set thefile [open $filename r]

	# rather than read one line at a time we read
	# all of the file in one go
	set filecontent [read $thefile]
	close $thefile

	# insert it into the text widget at line 1
	# character 0
	.filetext insert 1.0 $filecontent
}

proc saveFile {} {

	set filename [tk_getSaveFile]
        bind filename <Button-3> { popUpLabel }
	set thefile [open $filename w]

	# use the get command to get the text widget contents
	set filecontent [.filetext get 1.0 end]
	puts $thefile $filecontent
	close $thefile
}

proc popUpLabel { } {
  label .l
  button .l.b1 -text &quot;button1&quot; -bg white -command { puts &quot;test&quot; }
  button .l.b2 -text &quot;button2&quot; -bg grey  -command { puts &quot;test&quot; }
  pack .l .l.b1 .l.b2      

}

frame .buttonframe
button .buttonframe.open -text &quot;Open&quot; -command openFile
button .buttonframe.save -text &quot;Save&quot; -command saveFile

text .filetext

pack .buttonframe.open -side left
pack .buttonframe.save -side left
pack .buttonframe

pack .filetext


 
The second argument of the bind command is a tag.
If this tag is the path of a window the binding applies when the event occurs for this window.
Else, the tag is commonly a class of windows and this class and its windows are associated thru the bindtags command.
Examples of bindings:
Code:
  # this binding applies to the root window:
  bind . <3> {tk_messageBox -message Hi!}
  # the binding applies to all buttons:
  bind Button <3> {tk_messageBox -message Ouch!}
  pack [button .b -text Quit -command exit]
  # note that a right-click on the button activates the two callbacks
Some widgets permit to associate bindings to elements (text, canvas).
The OpenFile dialog (that can be a native dialog) has no way to associate a binding to a file name.
But you can create your own dialog and implement such a binding. This needs some work.

HTH

ulis
 
Hello ulis:
I am very Sorry, I still can not solve the problem.

I added the command of the &quot;bind . <3> { tk_getOpenFile }&quot; to my code. When I open the file dialog box and click right mouse on it, it doesn't work. But after I load a contains of file on to the window, if I right click on the window, it will come out a file dialog box.

And I also added another code of the &quot;bind . <3> { tk_getSaveFile }&quot; to my code, when I click on the botton of the save, it does nothing,but when I click on the right mouse on to the save button, it bring out a file dialog.

And another question is that how can I call to popUpLabel function, when I right click on the file dialog. Because I can not add an option of the &quot;-command popUpLabel&quot; to the tk_getOpenFile and tk_getSaveFile.

I redescribe my application again. I want to have a right click mouse for the file dialog box, and it cantains 3 function for copy, paste, delete file or directory from file diaolog box.

Could you help me please.

Thanks

Code:
proc openFile {} {
    # use the built in file selection dialog
    set filename [tk_getOpenFile -title testOpen ]
    bind . <3> { tk_getOpenFile }
    set thefile [open $filename r]

    # rather than read one line at a time we read
    # all of the file in one go
    set filecontent [read $thefile]
    close $thefile

    # insert it into the text widget at line 1
    # character 0
    .filetext insert 1.0 $filecontent
}

proc saveFile {} {

    set filename [tk_getSaveFile] 
    bind . <3> { tk_getSaveFile -title testSave }   
    set thefile [open $filename w]
    

    # use the get command to get the text widget contents
    set filecontent [.filetext get 1.0 end]
    puts $thefile $filecontent
    close $thefile
}

proc popUpLabel { } {
 
  label .l
  button .l.b1 -text &quot;copy&quot; -bg white -command { puts &quot;copy&quot; }
  button .l.b2 -text &quot;paste&quot; -bg grey  -command { puts &quot;paste&quot; }
  button .l.b3 -text &quot;delete&quot; -bg grey  -command { puts &quot;delete&quot; }
  pack .l .l.b1 .l.b2 .l.b3    

}

frame .buttonframe
button .buttonframe.open -text &quot;Open&quot; -command openFile
button .buttonframe.save -text &quot;Save&quot; -command saveFile

text .filetext

pack .buttonframe.open -side left
pack .buttonframe.save -side left
pack .buttonframe

pack .filetext
 
Sorry, Stewang, I tried to said you that you cannot do what you want. The dialog you are using has no support to do that.

ulis
 
Thanks ulis, I am sorry that I misunderstood what you said, and I tyied to find some reference meterial from website.

Thanks for your time.

rgds
stewang
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top