Weird error I receive from Tkinter in Python - python

I am attempting to make a tkinter project but as I tried to run for like the third time it gives me this error:
Traceback (most recent call last):
File "/Users/cool/Documents/STM Wisepay Service.py", line 63, in <module>
app = App(root)
File "/Users/cool/Documents/STM Wisepay Service.py", line 20, in __init__
self.create_buttons()
File "/Users/cool/Documents/STM Wisepay Service.py", line 30, in create_buttons
tk.Button(button_frame, text = "Add to Debt", commmand = self.debt).grid(column = 6, row = 5)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2366, in __init__
Widget.__init__(self, master, 'button', cnf, kw
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2296, in __init__
(widgetName, self._w) + extra + self._options(cnf)
_tkinter.TclError: unknown option "-commmand"
What can I do to fix this? What are the problems with my code?
Here is my code:
https://pastebin.com/mWPEFbpz

You are spelling command wrong (three m's)
You are passing it a variable called commmand and it doesn't know how to use that variable.
tk.Button(... commmand = ...
You can see it in the error message right here
_tkinter.TclError: unknown option "-commmand"
These python error messages are actually very helpful. I would encourage you to read them carefully to catch stuff like this.

Related

tkinter picture error: bad screen distance

I'm trying to write a tkinter program, and I came across an error that I've never seen before while working with tkinter. I've searched around everywhere, and tried everything I can think of. This is my code so far:
x=tk.Canvas(top,width=1000,height=750,bg="grey")
x.pack()
y=tk.PhotoImage(file="C:\\Users\\Admin\\Desktop\\images (3)_CnyokaDvJmG1xu.png")
x.create_image(top,0,0,image=y)`
and this is error
Traceback (most recent call last):
File "C:\Users\Admin\Anaconda3\lib\tkinter\__init__.py", line
1705, in __call__
return self.func(*args)
File "C:/Users/Admin/.spyder-py3/temp.py", line 16, in open
x.create_image(top,0,0,image=y).pack()
File "C:\Users\Admin\Anaconda3\lib\tkinter\__init__.py", line
2489, in create_image
return self._create('image', args, kw)
File "C:\Users\Admin\Anaconda3\lib\tkinter\__init__.py", line
2480, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: bad screen distance "."
You don't have to supply containing widget when placing an image in a canvas, coordinates are enough:
x.create_image(0,0,image=y)
The error is because canvas does not accept a widget as coordinates.

tkinter.Text() error (_tkinter.TclError : expected integer, got "sans")

I get this error from tkinter.Text():
>>> import tkinter
>>> tkinter.Text()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 3095, in __init__
Widget.__init__(self, master, 'text', cnf, kw)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: expected integer but got "sans"
or even tkinter._test() :
>>> tkinter._test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 3985, in _test
label = Label(root, text=text)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2760, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: expected integer but got "sans"
The message is pretty clear, but I don't know where to start.
EDIT : I got this error when I tried to use matplotlib.pyplot.plot(). But this worked (no error anymore) for matplotlib. I didn't find a similar way to deal with tkinter.
I am not getting any kind of error with the same code, so I can't debug it. So, I think you should try the following:
from tkinter import *
root=Tk()
log = Text(root, state='disabled', width=80, height=24, wrap='none')
log.grid()
root.mainloop()
If it doesn't work and other widgets like, buttons and entries don't work then there is something wrong with the tkinter that you have installed. So, try to unistall and then, reinstall tkinter:
sudo apt-get remove python3-tk
sudo apt-get install python3-tk
If the above gives an error,use this link to check for your your version of linux, how to do it (refer to the comments also) :
Install tkinter for Python
Try it and let me know if that helps.

Tkinter PhotoImage error "encountered an unsupported criticial chunk type "iDOT""

I am trying to show an image on screen with python and tkinter, but when I run it, it gives an error in the PhotoImage object.
This is my code:
from tkinter import *
root = Tk()
photo = PhotoImage(file="devil.png")
label = Label(root, image=photo)
label.pack()
root.mainloop()
The image file is in the same folder as the .py file.
And it gives this error:
Traceback (most recent call last):
File "C:/Users/MyUsername/PycharmProjects/GUI test/home.py", line 5, in <module>
photo = PhotoImage(file="devil.png")
File "C:\Users\MyUsername\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\MyUsername\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3498, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "iDOT"
Does anyone know how to fix this?
The chunk type of image you're using, 'iDOT', is not a registered PNG chunk. So, you should replace the image with an appropriate one.
This can help you understand what actually error is about

Tkinter (Python 3.5): TypeError when calling `.configure` on a label object

I have a label object that needs to display a variety of images. Based on my research, the following script (below) should successfully update the image displayed in my label object. However, when I call self.ImageViewer.configure(image=self.imgToDisp), I get a TypeError (seen below).
I'm not entirely sure what the error means, but it looks like .configure is expecting a string? Nobody else seems to encounter this problem so I must be doing something syntactically wrong with the script below. Any input is appreciated.
Script:
def getImgs(self):
folderPath = filedialog.askdirectory()
self.imgArray, self.imagePaths = batchImpt.importAllImgs(folderPath)
halThrThsnd.saveAllData(self.imgArray)
im = Image.open(self.imagePaths[0])
self.imgToDisp = PhotoImage(im)
self.imageViewer.configure(image = self.imgToDisp)
self.imageViewer.image = self.imgToDisp
Error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\biegad1\AppData\Local\Continuum\Anaconda3\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "//mspm1bnas50s/home58/biegad1/Python Scripts/GUI_0_1.py", line 40, in getImgs
self.imageViewer.configure(image = self.imgToDisp)
File "C:\Users\biegad1\AppData\Local\Continuum\Anaconda3\lib\tkinter\__init__.py", line 1330, in configure
return self._configure('configure', cnf, kw)
File "C:\Users\biegad1\AppData\Local\Continuum\Anaconda3\lib\tkinter\__init__.py", line 1321, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TypeError: __str__ returned non-string (type TiffImageFile)
You need to change self.imgToDisp = PhotoImage(im) to self.imgToDisp = ImageTk.PhotoImage(im)
Of course, you must add ImageTk to your import statements. I think you already did: from PIL import Image. If So, modify it to: from PIL import Image, ImageTk.

Tk window returns AttributeError: __len__

Here I'm starting to create a TK window with a text field but when ever I run this I get the error
Exception in Tkinter callback
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1470, in __call__
return self.func(*args)
File "School.py", line 31, in begin
emulatorI=emulator()
File "School.py", line 20, in __init__
code.pack(self.root)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1868, in pack_configure
+ self._options(cnf, kw))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1105, in _options
cnf = _cnfmerge(cnf)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 114, in _cnfmerge
for c in _flatten(cnfs):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1826, in __getattr__
return getattr(self.tk, attr)
AttributeError: __len__
from within the module. What am I doing wrong? I'm realitively new to classes so I may have done something wrong in the class setup.
I'm running python 2.7 on OS 10.9
class emulator:
def __init__(self):
self.root=Tk()
self.root.geometry("500x500")
self.root.title("Python")
code=Text(self.root)
code.pack(self.root)
self.root.mainloop()
emulatorI=emulator()
The problem is with the line
code.pack(self.root)
The pack function normally takes no arguments except keyword arguments, and so should just be called as
code.pack()
The reason for the very odd error is that pack can take a positional argument, which is expected to be a dictionary of options. When trying to treat the Tk instance as a dictionary, it failed due to the lack of a __len__ method.
What is the purpose of code.pack(self.root)?
The arguments for pack are placement directions, such as side, padding, fill, anchor, etc
(see http://effbot.org/tkinterbook/pack.htm ).

Categories

Resources