Reputation: 815
I am trying to create a drop-down menu in TCL/TK . I came across some examples and tried , the code is shown below
. configure -width 400 -height 400
label .header -text "Bitfields"
place .header -x 5 -y 0
entry .name -textvar username
label .username -text "F_name"
place .name -x 60 -y 20
place .username -x 2 -y 20
toplevel .win
menu .win.menubar
.win configure -menu .win.menubar
set m .win.menubar
menu $m.w_axs
$m add cascade -menu $m.w_axs -label W_AXS
$m.w_axs add command -label "write" -command "write"
$m.w_axs add command -label "read" -command "write"
This is creating a separate window , but I need it in the same window with the other entries. Tried googling for answers but couldn't find any.
Upvotes: 3
Views: 2434
Reputation: 15163
Simple: don't create a new toplevel, add the menu as descendant of the .
window.
. configure -width 400 -height 400
label .header -text "Bitfields"
place .header -x 5 -y 0
entry .name -textvar username
label .username -text "F_name"
place .name -x 60 -y 20
place .username -x 2 -y 20
menu .menubar
. configure -menu .menubar
set m .menubar
menu $m.w_axs -tearoff 0
$m add cascade -menu $m.w_axs -label W_AXS
$m.w_axs add command -label "write" -command "write"
$m.w_axs add command -label "read" -command "write"
PS: I added the -tearoff 0
, you probably want this. (It is by default 1 to support old applications that support/relay on it)
Upvotes: 4