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

some more Menu Problems

Status
Not open for further replies.

akpr

Programmer
Jul 25, 2001
19
0
0
US
Problem 1
How do I bind <MOTION> in menu
i.e.
I want to display the brief note about the menu to status bar. I create a status.
I tried to bind MOTION event as follows but no result
set menu_name [CreateMenu .menu.menubar filemenu &quot;File&quot; 0]
$menu_name add command -label &quot;New&quot; -command { puts &quot;Open&quot; } -underline 0 -font actual
$menu_name add command -label &quot;Open&quot; -command { exit } -underline 1 -font actual
bind $menu_name <Motion> { .stausbar SetText &quot;AAA&quot; }
but it is not working then tried as follows
bind all <Motion> { .stausbar SetText &quot;AAA&quot; } -> again no result

Problem 2
How do bind Short cut key for menu I mean ATL-f.
 
Here's a little program that might help you some. I put messages in the status when you move the mouse over FILE or QUIT. Cut and paste it and give it a try...

************** Top of Program ******************
#!/bin/sh
# the next line restarts using wish exec wish &quot;$0&quot; &quot;$@&quot;

eval destroy [winfo child .]

global w

set w .menu
catch {destroy $w}
toplevel $w
wm title $w &quot;Menu Demo&quot;
wm minsize $w 100 20
wm geometry . +0+0

proc displayMainWindow {} {

global w

set menustatus &quot;No Message&quot;

menu $w.menu -tearoff 0
set m $w.menu.file
menu $m -tearoff 0

$w.menu add cascade -label &quot;File&quot; -menu $m -underline 0
$m add command -label &quot;Open&quot; -command {}
$m add separator

set m $w.menu.quit
menu $m -tearoff 0

$w.menu add cascade -label &quot;Quit&quot; -menu $m -underline 0
$m add command -label &quot;Exit&quot; -command {exit}
$m add separator

$w configure -menu $w.menu

bind Menu <<MenuSelect>> {
global $menustatus
if {[catch {%W entrycget active -label} label]} {
set label &quot; &quot;
}
if {$label == &quot;File&quot;} {
set menustatus &quot;This is a File&quot;
} elseif {$label == &quot;Quit&quot;} {
set menustatus &quot;Now we can QUIT&quot;
} else {
set menustatus &quot;No Message&quot;
}
update idletasks
}

set menustatus &quot; &quot;
frame $w.statusBar
label $w.statusBar.label -textvariable menustatus -width 20 -relief sunken -bd 1 -font &quot;Helvetica 10&quot; -anchor w
pack $w.statusBar.label -side left -padx 2 -expand yes -fill both
pack $w.statusBar -side bottom -fill x -pady 2

}

displayMainWindow;

************** Bottom of Program ****************
 
akpr asked, &quot;Problem 2: How do bind Short cut key for menu I mean ATL-f.&quot;

I like simple problems like this. When you create your menu items, just use the -underline option to specify which character of the label you wanted underlined. Then Tcl automatically takes care of creating the bindings needed to implement the keyboard shortcut. Because it's so easy, I always include keyboard shortcuts for my menus.

For example:

[tt]. configure -menu .mbar
menu .mbar

# Add a File menu, underline the &quot;F&quot;

.mbar add cascade -label &quot;File&quot; -underline 0 -menu .mbar.file

menu .mbar.file

# Add a &quot;Open&quot;, &quot;Save&quot;, and &quot;Save as...&quot;
# items, underline the &quot;O&quot;, &quot;S&quot;, and &quot;a&quot;

.mbar.file add command -label &quot;Open&quot; -underline 0 -command { OpenFile }
.mbar.file add command -label &quot;Save&quot; -underline 0 -command { SaveFile }
.mbar.file add command -label &quot;Save as...&quot; -underline 5 -command { SaveFile }[/tt]
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Hi
Thanks for ur help.
I do not think it &quot;-underline 0&quot; is going to work. I spent 2 day to get it work. I agree the &quot;-underline 0&quot; will get displayed a line under the first character. but once u press ALT-f nothing happens. After reading ur examples I tried again but -
 
Hi
I am sorry about that , it is the problem with my code. I have find out what's going on. Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top