tkinter.TclError: invalid command name "table" - python

Okay, first of all I don't know what is the actual problem here so I couldn't come up with a more accurate title. Maybe some of you can edit it to make it accurate
The following is the minimalised code to reproduce the problem I'm having.
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()
The cal and the trabar are these files http://tkinter.unpythonic.net/wiki/TkTableCalendar and https://github.com/Infinidat/infi.systray/blob/develop/src/infi/systray/traybar.py respectively.
If you run this, it will make a icon in the system tray of a windows machine with the options Add and Quit. clicking on the app opens up the calender, no problem. Close the calender and click on the Add again. But this time it doesn't open the calendar and throws the following error
`
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"
`
This problem only appears when I use SysTrayIcon with the Calendar.Instead of Calendar if you use simple Tkinter Button or Label etc. this error doesn't appear. Also I can use the Calendar widget normally (without the SysTrayIcon ) in a usual Tkinter GUI as many times as I want, no error occur there. Now I don't have any clue about whats happenning here and how to fix this. What problem does SysTrayIcon have with Calendar and Why the error doesn't happen the first time I open the GUI? Please help.

TkTableCalendar requies the tktable module, which you have installed in lib-tk (3rd party modules usually go into lib/site-packages) as indicated by this part of the traceback.
File "C:\Python27\lib\lib-tk\tktable.py", line 118, in __init__
Tkinter.Widget.__init__(self, master, 'table', kw)
The tktable module requires that your tcl/tk installation have the tktable extension. That extension defines the 'table' widget. It is not part of the standard tcl/tk that is installed with Python on Windows. Hence
_tkinter.TclError: invalid command name "table"
The tktable source code (probably a mixture of tcl and C) is hosted at SourceForge. This page says that it is part of the ActiveState Batteries Included distribution. I don't know if the free version of AS tcl/tk has all the 'batteries'. And I don't know how to replace the tcl/tk installation you already have with a new one. I personally would use an alternative if possible.

Related

Python Tkinter --AttributeError

Cannot seem to figure out the below Tkinter message. Usually doing a quick
search will provide answers but this time I seem to miffed the search engines as to
what might be causing the below error. Curious to know if I am missing a Python package or line 25 below is used in an older version of Python and it has been updated to
a newer command.
I am importing the following packages into the script:
from tkinter import *
from tkinter import filedialog
The function is suppose to save any typed text put into a text area. It does save the file but the file is empty.
Thanks,
Kurt
C:\Users\kurt>python --version
Python 3.10.4
def saveFiles():
filename = filedialog.asksaveasfile(
mode='w',
title="Save a File",
defaultextension=".txt"
)
filename.config(mode='w') ------------> **This is line 25**
pathh.insert(END, filename)
data = str(txtarea.get(1.0, END))
filename.write(data)
filename.close()
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\kurt\Documents\Scripts\TKinter\fileExplorerReadFile.py", line 25, in saveFiles
filename.config(mode='w')
AttributeError: '_io.TextIOWrapper' object has no attribute 'config'
The error is saying that the object returned by the asksaveasfile method doesn't have a config method.
tkinter.filedialog.asksaveasfile(mode='w', **options)¶
Create a SaveAs dialog and return a file object opened in write-only mode.
When you call the asksaveasfile method, it automatically returns a file object in write mode already so there is no need for any further configuration to write to the file. If you were to omit the line throwing the error, your code should work the way you intended.

How to get source code of current module when the code is compiled using pyinstaller

In my GUI application written in Python with Tkinter, I'm trying to add a new tab to the Notebook widget named "Source Code" which would get the source code using inspect module and show it with IDLE's syntax highlighting in a Text widget.
from tkinter import Frame, Text
from idlelib.percolator import Percolator
from idlelib.colorizer import ColorDelegator
class sourceFrame(Frame):
def __init__(self, master, **kwargs):
super().__init__(master=master, **kwargs)
self.sourceText = Text(self, state="disabled", wrap="none", bg="white", relief="flat", takefocus=0, highlightthickness=0)
Percolator(self.sourceText).insertfilter(ColorDelegator())
self.sourceText.replace(inspect.getsource(__import__("sys").modules[__name__]))
self.sourceText.pack(expand=1, fill="both")
The above code works perfectly fine when I run the code normally. However, when I pack the code to an *.exe file using pyinstaller and run the *.exe, I get an error:
Traceback (most recent call last):
File "main.pyw", line 102, in wrapper
File "main.pyw", line 2129, in __init__
File "main.pyw", line 2120, in __init__
File "main.pyw", line 2112, in __init__
File "inspect.py", line 1147, in getsource
File "inspect.py", line 1129, in getsourcelines
File "inspect.py", line 958, in findsource
OSError: could not get source code
Is there any way to get the source code of current module even if the code was compiled into an *.exe file?

idle crashing when I press configure idle

If I go on cmd and write python -m idlelib, that would open IDLE. If I were to then go on configure IDLE, on the cmd, it gives be an error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\editor.py", line 574, in config_dialog
configdialog.ConfigDialog(self.top,'Settings')
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 78, in __init__
self.create_widgets()
File "C:\Users\\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 113, in create_widgets
self.highpage = HighPage(note)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 693, in __init__
self.load_theme_cfg()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 998, in load_theme_cfg
self.paint_theme_sample()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 1279, in paint_theme_sample
self.highlight_sample.tag_config(element, **colors)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3854, in tag_configure
return self._configure(('tag', 'configure', tagName), cnf, kw)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1627, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid color name "#00224"
I probably have a custom theme with an invalid color, however, how am I supposed to delete it if I can't access it (since it crashes when I do so).
There was a post, Python freezes when configuring IDLE that had I believe the same issue, but all he says as a solution is "manually deleting the faulty theme", which he doesn't explain. Pretty much, I want to access configure IDLE option without it crashing. Once it does crash, the only way I can close it then is by using task manager or restarting my computer.
As solution, you can tell me how to delete a custom theme without using IDLE if that's possible.
If the problem is in a custom theme, then the user configuration file you need to edit is $HOME/.idlerc/config-highlight.cfg. In your case, $HOME, based on the url below, appears to be C:/Users/chess. Just add a digit to make six. You can use the IDLE editor to do so. You should then be able to edit the color properly in the config dialog.
The problem might possibly be a character missing from the defaults file supplied with IDLE:
C:\Users\chess\AppData\Local\Programs\Python\Python38-32\lib\idlelib\config-highlight.def
Thank you for opening IDLE in a console, getting the traceback, and posting all of it. It gave me an idea of how to prevent the crash, so I opened a bug report

Set up Python tkTable

Being very new to Phyton, I’m trying to use tktable for Python and can’t get it run on my PC.
After searching a lot in the net, without finding any solution, I hope you find the time to help me a bit.
I’m sure this is peanuts for you.
I’m running Python 3.7 on a Windows 8.1. PC.
I’m getting this error:
_tkinter.TclError: invalid command name "table"
What I did so far:
Downloaded tktable and run the setup.py.
Copied the tktable.py to the Python site-packages folder.
Installed ActiveTcl.
Copied the three files tktable.tcl, Tktable.dll and pkgIndex.tcl from ActiveTcl (C:\ActiveTcl\lib\Tktable2.11) to C:........\Python\Python37-32\tcll\Tktable2.11.
According what I have found in the net, this should do it…
But, as I wrote, I keep getting the error I mentioned.
Michael
The content is:
C:\Users\mschuppisser.EAD\AppData\Local\Programs\Python\Python37-32\Lib\;
C:\Users\mschuppisser.EAD\AppData\Local\Programs\Python\Python37-32\DLLs\
Traceback:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\mschuppisser.EAD\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/mschuppisser.EAD/Data/My Data/Python/Test Applikation/Test Applikation.py", line 267, in Jump_to_UebersichtsFenster3
application = clsUebersichtsFenster3(UebersichtsFenster3)
File "C:/Users/mschuppisser.EAD/Data/My Data/Python/Test Applikation/Test Applikation.py", line 447, in __init__
self.table_grid = tktable.Table(UebersichtsFenster3) # , state='disabled', width=50, titlerows=1, rows=5, cols=4, colwidth=20)
File "C:\Users\mschuppisser.EAD\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tktable.py", line 135, in __init__
tkinter.Widget.__init__(self, master, 'table', kw)
File "C:\Users\mschuppisser.EAD\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2299, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: invalid command name "table"

Enthought Mayavi embedding with wx problems

At first my running system:
I use Windows 8 Pro and Mayavi 4.3 from the repository together with wxPython 2.9.4.0 at Python 2.7.4 but also had the same issue with mayavi 4.2.1 from the EPD package...
As I try to embedd mayavi into a notebook panel I get some problems with the UI. Even in the demo file from mayavi I got the same strange behavior of external frames generated by mayavi.
So using the settings button a the settings window opens. Also the scene reacts on the parameters I changed using the settings. But after clicking OK or chancel the window does not close. And python gives back several error messages. A simular behavior was there as i used the pipeline by implenting mlab.show_pipeline() command.
This behaivior is could be found on the sample from the enthought web page too.
Here you can see my error message after trying to click OK in the settings frame of the enthougth example:
C:\my_directory\>python wx_embedding.py
C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\toolkit.py:35: wxPyDeprecationWarning: Using deprecated class PySimpleApp.
_app = wx.PySimpleApp()
wx_embedding.py:63: wxPyDeprecationWarning: Using deprecated class PySimpleApp.
app = wx.PySimpleApp()
Traceback (most recent call last): File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\ui_live.py", line 360, in _on_ok
self.close( wx.ID_OK )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\ui_live.py", line 320, in close
ui.finish()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 264, in finish
self.reset( destroy = True )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 304, in reset
editor.dispose()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\instance_editor.py", line 208, in dispose
self._ui.dispose()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 237, in dispose
self.finish()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 264, in finish
self.reset( destroy = True )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 318, in reset
toolkit().destroy_children( self.control )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\toolkit.py", line 474, in destroy_children
control.DestroyChildren()
File "C:\Python27\lib\site-packages\wx-2.9.4-msw\wx\_core.py", line 9203, in DestroyChildren
return _core_.Window_DestroyChildren(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "GetEventHandler() == this" failed at . .\..\src\common\wincmn.cpp(468) in wxWindowBase::~wxWindowBase(): any pushed event handlers must have been removed
Thanks in advance
Mayvi is not compatible with wx 2.9.
More info here: https://support.enthought.com/entries/22601196-wxPython
Please use enpkg to revert to wx 2.8 which ships with EPD.
At least this particular exception can be solved with the changes associated with this PR: https://github.com/enthought/traitsui/pull/108. I don't know about Mayavi and the rest of the stack yet, but that change will at least get traitsui working with wxPython 2.9.

Categories