Reputation: 79
Is there any way to create a drop down toolbar button(Like Paste button in MS Word) using Tcl/TK?.I have googled a lot but nothing found.Any help will be appreciable.
Upvotes: 0
Views: 1544
Reputation: 137567
You probably want to use a menubutton
and a menu
, probably with radiobutton
entries if I've understood which UI element in Word you're talking about. (Or maybe a ttk::menubutton
and menu
.) Now, if you're doing something very simple with it then you can make do with just tk_optionMenu
as a way to combine those commands, but that's just a simple procedure; if you're doing something complicated with the menu, it's probably easier to write it yourself or at least to get the code for tk_optionMenu
and to customise it how you want it to work.
The source code for tk_optionMenu
isn't very long; I'll paste the non-comment parts of it here:
proc ::tk_optionMenu {w varName firstValue args} {
upvar #0 $varName var
if {![info exists var]} {
set var $firstValue
}
menubutton $w -textvariable $varName -indicatoron 1 -menu $w.menu \
-relief raised -highlightthickness 1 -anchor c \
-direction flush
menu $w.menu -tearoff 0
$w.menu add radiobutton -label $firstValue -variable $varName
foreach i $args {
$w.menu add radiobutton -label $i -variable $varName
}
return $w.menu
}
You probably want to pay attention to how the menubutton
and menu
are connected to each other. ttk::menubutton
is mostly a drop-in replacement for menubutton
, except for different look-and-feel configuration options.
Upvotes: 1