鼠标事件与Tk菜单命令重复,而不是加速键

时间:2016-10-11 03:55:15

标签: menu tcl mouseevent tk

这个问题与64位Win7上的Tcl / Tk 8.5.9(通过starkit运行时)和8.6(通过TkCon 2.7)有关,并让我回到我写过的第一个Tk脚本。有以下内容:

menu .menubar
. config -menu .menubar
menu .menubar.file -tearoff 0
.menubar add cascade -label "File" -menu .menubar.file -underline 0
.menubar.file add command -label "Test" -command {puts "Test"}

调用"测试"菜单命令以图形方式,我得到"测试"在stdout两次,好像按钮释放事件是重复的。使用分配给此菜单命令的键盘加速器,键命令按预期工作(即仅执行一次命令)。

窗口小部件配置选项如下所示:

% .menubar.file configure
{-activebackground activeBackground Foreground SystemHighlight SystemHighlight} {-activeborderwidth activeBorderWidth BorderWidth 0 1} {-activeforeground activeForeground Background SystemHighlightText SystemHighlightText} {-background background Background SystemMenu SystemMenu} {-bd -borderwidth} {-bg -background} {-borderwidth borderWidth BorderWidth 0 1} {-cursor cursor Cursor arrow arrow} {-disabledforeground disabledForeground DisabledForeground SystemDisabledText SystemDisabledText} {-fg -foreground} {-font font Font TkMenuFont {{Segoe UI} 9}} {-foreground foreground Foreground SystemMenuText SystemMenuText} {-postcommand postCommand Command {} {}} {-relief relief Relief flat flat} {-selectcolor selectColor Background SystemMenuText SystemMenuText} {-takefocus takeFocus TakeFocus 0 0} {-tearoff tearOff TearOff 1 0} {-tearoffcommand tearOffCommand TearOffCommand {} {}} {-title title Title {} {}} {-type type Type normal normal}

% .menubar.file entryconfigure 0
{-activebackground {} {} {} {}} {-activeforeground {} {} {} {}} {-accelerator {} {} {} {}} {-background {} {} {} {}} {-bitmap {} {} {} {}} {-columnbreak {} {} 0 0} {-command {} {} {} {puts "Test"}} {-compound compound Compound none none} {-font {} {} {} {}} {-foreground {} {} {} {}} {-hidemargin {} {} 0 0} {-image {} {} {} {}} {-label {} {} {} Test} {-state {} {} normal normal} {-underline {} {} -1 -1}

Mac上的8.5不会出现此问题。

虽然我没有使用Python,但我看到许多材料暗示了Python和Tkinter这样的东西。我也想知道这是否与我的Win框上的鼠标有关,虽然在这台机器和Mac之间交换相同的鼠标不会改变上面的行为。

有没有人见过这个?

更新:偶然地,我碰巧注意到当我允许菜单被撕掉,然后当我调用撕开时,实际上有两个文件菜单窗口被创建。当我将它们分开时(即拖动它们使它们彼此不重叠),单独单击每个Test菜单条目会导致命令仅被调用一次。所以我不知何故创建了重复的菜单。 (这是来自TkCon 2.7的8.6.4 / 8.6.4。)

0 个答案:

没有答案