I am getting an error whenever I try to import the tkinter module. I'm using Python 3.4 so the capital T isn't an issue.
from tkinter import *
root = Tk()
root.mainloop()
It throws back an error like:
Traceback (most recent call last):
File "<string>", line 420, in run_nodebug
File "<module1>", line 11, in <module>
File "C:\Python34\lib\tkinter\__init__.py", line 3372
t self.tk.call(('image', 'create', imgtype, name,) + options)
^
SyntaxError: invalid syntax
Thanks for the help!
The problem seems to be somehow existing in the init file itself. Just go to the file in your pc.
C:\Python34\lib\tkinter\__init__.py
Edit that init.py with Idle or whatever IDE you use. Next go to the line number 3372 and remove that unwanted character 't' from the line
t self.tk.call(('image', 'create', imgtype, name,) + options)
It'll do the work for you.
Related
This is my code:
from tkinter import *
logoImage = PhotoImage(file='logo.png')
logoLabel = Label(root, image=logoImage, bg='dodgerblue3')
logoLabel.grid(row=0, column=0)
The image is in the same directory as the project. In fact, when I open it with cmd or Python it works. But when I use VS Code or Turn it into .exe file, it shows this error:
Traceback (most recent call last):
File "c:\Users\Simo\OneDrive\Python\Scientific calculator\calc.py", line 180, in <module>
logoImage = PhotoImage(file='logo.png')
File "C:\Users\Simo\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Simo\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 open "logo.png": no such file or directory
How can I fix this?
Maybe try putting the file into your workspace and using the relative path.
Every time, even though I have the source file, the same error message appears - 'Tcl error...could not recognize data in image file'. The problem also occurs with other images present in my disk drive.
Here is the code:
from tkinter import *
window=Tk()
window.geometry("420x420")
window.title('My first GUI programme')
source='D:\\Desktop\\op.jfif'
icon=PhotoImage(file=source)
window.iconphoto(True, icon)
window.mainloop()
Here goes the error:
PS D:\Documents\pythonProject> & "C:/Program Files (x86)/Python/python.exe" "d:/Documents/pythonProject/Learning python/Practice.py"
Traceback (most recent call last):
File "d:\Documents\pythonProject\Learning python\Practice.py", line 6, in <module>
icon=PhotoImage(file=source)
File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 4064, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 4009, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "D:\Desktop\op.jfif"
I don't know if there is any problem with my code or i need to change any settings. I would be thankful to you if you provide me any assistance.
I managed to do this by changing the file extension and file content of my image file to 'png' which worked in python.
Python Tkinter supports GIF, PGM, PPM, and PNG. So, try changing the extension of the file to one of them
i see your problem
i also have the same problem
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"
I'm using python's Turtle Graphics and I want to set a background picture. However, it's not working. I need an answer quick as I have an assignment for my Computer Science class tomorrow >_<. Here's my code:
import time
import sys
import turtle
##Render
turtle.bgpic("background.png")
##End
turtle.done()
And I'm getting this error:
Traceback (most recent call last):
File "C:/Users/Alfie/Desktop/Youtube Game/Youtube.py", line 6, in <module>
turtle.bgpic("background.png")
File "<string>", line 8, in bgpic
File "C:\Python27\lib\lib-tk\turtle.py", line 1397, in bgpic
self._bgpics[picname] = self._image(picname)
File "C:\Python27\lib\lib-tk\turtle.py", line 503, in _image
return TK.PhotoImage(file=filename)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3366, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3320, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't recognize data in image file "background.png"
Followed with a Not Responding screen. Anyone know what the error is?
Tk only supports GIF, PGM and PPM according to this question. Your turtle library uses Tk internally and so you have to use a GIF file for your background.
I have tried that function.
I have used format .png --> OK
Remember \\ instead of \
ex: turtle.bgpic("""C:\\Users\\ASUS\\Downloads\\test.gif""")
--> So I think at that time, we can use .png in Python turtle.
I'm trying to change the background image in a turtle window.
The code reads simply as this:
import turtle
turtle.bgpic("france53.gif")
The turtle window shows up blank and I get the following error message:
Traceback (most recent call last):
File "<ipython-input-25-45373f8f3ea2>", line 1, in <module>
bgpic("france53.gif")
File "<string>", line 1, in bgpic
File "/Users/danielcharrier/anaconda/lib/python3.4/turtle.py", line 1482, in bgpic
self._setbgpic(self._bgpic, self._bgpics[picname])
File "/Users/danielcharrier/anaconda/lib/python3.4/turtle.py", line 738, in _setbgpic
self.cv.itemconfig(item, image=image)
File "<string>", line 1, in itemconfig
File "/Users/danielcharrier/anaconda/lib/python3.4/tkinter/__init__.py", line 2416, in itemconfigure
return self._configure(('itemconfigure', tagOrId), cnf, kw)
File "/Users/danielcharrier/anaconda/lib/python3.4/tkinter/__init__.py", line 1310, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: image "pyimage12" doesn't exist
The file "france53.gif" is in the working directory. What should I do to make it work?
I'm using the Anaconda distribution for Mac OS X.
Thanks!