我正在尝试在 TCL/TK 中创建一个下拉菜单。我遇到了一些例子并尝试了,代码如下所示
. 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"
这是创建一个单独的窗口,但我需要它与其他条目在同一个窗口中。尝试使用谷歌搜索答案,但找不到任何答案。
最佳答案
简单:不要创建新的顶层,将菜单添加为 .
窗口的后代。
. 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:我添加了 -tearoff 0
,您可能需要这个。 (默认为 1 支持支持/中继它的旧应用程序)
关于tcl - TCL/TK 中的 menubutton 用法在同一窗口中创建下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589577/