tcl - TCL/TK 中的 menubutton 用法在同一窗口中创建下拉菜单

标签 tcl tk-toolkit

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

相关文章:

tcl - 是否可以更改笔记本标签的宽度?

c - 如何在TCL中运行预编译的C代码?

syntax - 为什么 Tcl 在调用 "set"时不在变量名前使用美元符号?

tkinter - 按键时关闭 tk 窗口

linux - 在Linux中使用Tk运行Perl程序报错 "1132148 is not a hash"

linux - 如何从 tcl 脚本记录 xterm 窗口

dependencies - 获取modelsim中vhdl实体的依赖关系

python - Tkinter/ttk 帧大小

python - 更改 tkinter 窗口中按钮的位置

fonts - 如何更改 ttk::button (主题小部件)中的字体和字体大小?