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.
Related
from tkinter import *
window = Tk()
window.geometry("500x500")
icon = PhotoImage(file="X.png")
window.iconphoto(True,icon)
window.mainloop()
#my code
#error
Traceback (most recent call last):
File "C:\Users\priya\PycharmProjects\pythonProject2\main.py", line 5, in <module>
icon = PhotoImage(file="X.png")
File "C:\Users\priya\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\priya\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "X.png"
It seems that the file X.png is not a valid PNG image file, try viewing it in a image viewer and check its filetype via https://www.checkfiletype.com/ or using the file command via WSL.
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.
I have declared an image file within a class and I'm able to show it in the class body. But when I am calling it within a function to show it within the function body it throws an error.
Here is my code:
import tkinter
from tkinter import *
from PIL import Image,ImageTk
body=Tk()
ftpim = Image.open('textfile_big.png')
ftpfileimage = ImageTk.PhotoImage(ftpim)
lbl=Label(body,image=ftpfileimage).pack()
def nextimg():
cbody=Tk()
lbl=Label(cbody,image=ftpfileimage).pack()
but=Button(body,command=nextimg,text="show").pack()
body.mainloop()
When I'm executing it, however, I have the error "pyimage1" doesn't exist :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\My Love\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\Users\My Love\Desktop\New Folder\Unknown_Project\Unknown_package\sssss.py", line 10, in nextimg
lbl=Label(cbody,image=ftpfileimage).pack()
File "C:\Users\My Love\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2763, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\My Love\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2296, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist
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
Python 2.7/Windows: My understanding is that we can load custom mouse cursors using the cursor='#file.cur' syntax:
widget = tkinter.Label( ..., cursor='#help.cur' )
Here's the traceback I receive:
Traceback (most recent call last):
File "<pyshell#82>", line 1, in <module>
widget.config( cursor='#help.cur' )
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1202, in configure
return self._configure('configure', cnf, kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1193, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: bad cursor spec "#help.cur"
Is it possible to load custom mouse cursors under Windows using Tkinter, a Tkinter extension, or via a Win32 API call?
lbl=Label(root, text="toto", cursor="#toto.cur") works for me on Python 2.6 and Vista. Make sure that the cur file is in the working directory of your script (I have a similar traceback if I try to load a non-existing cursor) and that the file is not corrupted.
As an alternative, here is a list of internal cursors: http://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm