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

Newbie: Tk Menu Height Question (argh) 1

Status
Not open for further replies.

Raybert

Programmer
Jun 5, 2002
2
CA
Hi, please help me with this if you know the answer. :)

How do you set the size the height of the menubars in Tk?

I would like to increase the size of the menubar so that the buttons are big enough to be pressed on a touchscreen. The menu command doesn't seem to have a "-height" option.

I've spent a lot of time on this and haven't been able to figure out how to do this.

Is there a proper way to make the menubar thicker? If not, is there a kludge I can use?

Thanks!

Raybert
 
I'm afraid I'm not coming up with any good answers for you, Raybert.

You can specify the font you want to use for menus with the -font attribute. And if you want to set the font for all menus in your application, you can set a default value with in the option resource database, like this:

Code:
option add *Menu*font {Tahoma 36}

This gives me nice, big menu selections everywhere in my application. (See the option command reference page for more information on the option database.)

Okay so far. And this works fine when I test it on Linux. Unfortunately, it doesn't quite work on Windows (at least the Windows 2000 systems I have as of Tcl version 8.3.2). All cascade menus use the default font I specify, but I can't change the font for the menubar itself. I suspect that Tcl is hooking into the native Windows menu functions somehow, and is therefore ignoring the font settings.

Unfortunately, I've not figured out a workaround on Windows. I'll poke around a bit, and let you know if I turn up anything. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Okay, I've verified that the problem is because Tk hooks into the Windows native mechanisms for menubars. However, I was reminded of a workaround.

You can go back to the old way of creating menubars in Tcl specifically, you create several menubutton widgets, and pack them into a frame at the top of your window. This approach is generally deprecated in favor of the newer -menu option for toplevel windows, but I think it's going to be your only option in this situation if you're working on Windows.

Here's a quick example of how you'd build your menubar with menubuttons:

Code:
# Set up our default fonts

option add *Menu*font {Tahoma 32}
option add *Menubutton*font {Tahoma 32}

# Create a frame to hold the menubuttons

frame .mbar
pack .mbar -side top -anchor w

# Create a File menu

menubutton .mbar.file -text "File"     -underline 0 -menu .mbar.file.menu
pack .mbar.file -side left

menu .mbar.file.menu -tearoff 0
.mbar.file.menu add command     -label "Open" -underline 0
.mbar.file.menu add command     -label "Save As" -underline 0
.mbar.file.menu add command     -label "Quit" -underline 0

Unfortunately, the <Alt> accelerators don't seem to be installed automatically with menubuttons, so you'd have to create the bindings yourself. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks AviaTraining !

This will help a lot!

I actually use Win2000 :-( so I did run into that problem that you mentioned. I guess I'll have to use the menu buttons. At least I have a workable solution.

Raybert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top