【发布时间】:2016-07-20 15:53:40
【问题描述】:
好的,首先我不知道这里的实际问题是什么,所以我想不出更准确的标题。也许你们中的一些人可以对其进行编辑以使其准确
以下是重现我遇到的问题的最小化代码。
from traybar import SysTrayIcon
from cal import Calendar
import Tkinter
class Add():
def __init__(self,master):
Calendar(master).pack()
def add(systray):
root = Tkinter.Tk()
Add(root)
root.mainloop()
SysTrayIcon("abc.ico","abc", (('Add',None, add), ) ,default_menu_index=0).start()
cal 和 trabar 分别是这些文件 http://tkinter.unpythonic.net/wiki/TkTableCalendar 和 https://github.com/Infinidat/infi.systray/blob/develop/src/infi/systray/traybar.py。
如果你运行它,它将在 Windows 机器的系统托盘中创建一个图标,选项为 Add 和 Quit。点击app 打开日历,没问题。关闭日历并再次单击Add。但是这次它没有打开日历并抛出以下错误
`
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 314, in 'calling callback function'
File "C:\Users\Koushik Naskar\AppData\Roaming\Python\Python27\site-packages\traybar.py", line 79, in WndProc
self._message_dict[msg](hwnd, msg, wparam.value, lparam.value)
File "C:\Users\Koushik Naskar\AppData\Roaming\Python\Python27\site-packages\traybar.py", line 276, in _command
self._execute_menu_option(id)
File "C:\Users\Koushik Naskar\AppData\Roaming\Python\Python27\site-packages\traybar.py", line 283, in _execute_menu_option
menu_action(self)
File "C:\Users\Koushik Naskar\Desktop\So\temp.py", line 11, in add
Add(root)
File "C:\Users\Koushik Naskar\Desktop\So\temp.py", line 7, in __init__
Calendar(master).pack()
File "C:\Users\Koushik Naskar\Desktop\So\cal.py", line 66, in __init__
state='disabled', browsecommand=self._set_selection)
File "C:\Python27\lib\lib-tk\tktable.py", line 118, in __init__
Tkinter.Widget.__init__(self, master, 'table', kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2090, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: invalid command name "table"
`
仅当我使用SysTrayIcon 和Calendar 时才会出现此问题。如果您使用简单的Tkinter Button 或Label 等而不是Calendar,则不会出现此错误。我也可以在通常的 Tkinter GUI 中正常使用 Calendar 小部件(没有 SysTrayIcon ),只要我愿意,那里不会发生错误。现在我对这里发生的事情以及如何解决这个问题一无所知。 SysTrayIcon 与 Calendar 有什么问题,为什么我第一次打开 GUI 时没有发生错误?请帮忙。
【问题讨论】:
标签: python multithreading tkinter tcl tktable