Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TCL/TK中的菜单按钮用于在同一窗口中创建下拉菜单_Tcl_Tk - Fatal编程技术网

TCL/TK中的菜单按钮用于在同一窗口中创建下拉菜单

TCL/TK中的菜单按钮用于在同一窗口中创建下拉菜单,tcl,tk,Tcl,Tk,我正在尝试在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

我正在尝试在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"

附言:我添加了
-tearof0
,您可能想要这个。(默认情况下,它是1,以支持支持/中继它的旧应用程序)

您好,感谢它的工作,需要更多帮助,我如何在我的窗口中放置或定位此菜单,目前它位于顶部,我必须将其移动到任意(x,y)位置。试着用那个地方没用。哦,好吧。也许警察能帮上忙?