【问题标题】:Python Tkinter: Status bar not working if menu uses add_separatorPython Tkinter:如果菜单使用 add_separator,则状态栏不起作用
【发布时间】:2014-09-14 20:55:48
【问题描述】:

我在我的 GUI 中创建了一个带有 2 个选项的菜单,并且我还在这两个选项之间使用了 add_separator()。还有一个状态栏,当鼠标悬停在任何选项上时提供说明。

我的问题是,为什么分隔线之后的任何选项都没有在状态栏中提供任何描述?它改变了它的索引位置吗?

def helpMenuStatusBar(self, event = None):
   if self.parent.call(event.widget, "index", "active") == 0:
      self.statusBar.set("Select available files")
   elif self.parent.call(event.widget, "index", "active") == 1:
      self.statusBar.set("About This Application")
   else:
      self.statusBar.set("")

self.helpMenu = Menu(menubar, tearoff = 0, postcommand = self.updateMenu)
self.helpMenu.add_command(label = "Available files", command = self.availableFiles, state = "disabled")
self.helpMenu.add_separator()
self.helpMenu.add_command(label = "About", command = self.onAbout)
menubar.add_cascade(label = "Help", menu = self.helpMenu)
self.helpMenu.bind("<<MenuSelect>>", self.helpMenuStatusBar)

【问题讨论】:

  • 您是否尝试打印出活动项目索引以查看索引是否已更改?
  • 糟糕!感谢您的提醒!

标签: python menu tkinter statusbar


【解决方案1】:

添加分隔线后,这将算作菜单项之一。所以在这种情况下:

def helpMenuStatusBar(self, event = None):
   if self.parent.call(event.widget, "index", "active") == 0:
      self.statusBar.set("Select available files")
   elif self.parent.call(event.widget, "index", "active") == 2:
      self.statusBar.set("About This Application")
   else:
      self.statusBar.set("")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-18
    • 2014-12-06
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多