Python: Message error when using bgpic() from turtle module - python

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!

Related

weird error message in tkinter when UFD closes a window that's in use

I have a code that constantly updates a clock and it's like this:
class countdown:
#initiatiate stuff
def count(self):
# countdown
# update textbox with the correct time
self.countdown_complete = customtkinter.CTkButton(self.countdownWindow,width=100, height =30, text="Complete", font=("Verdana",18), command = lambda: self.save_info(self.timer, i),fg_color=self.lightbutton, text_color=self.lightfont, hover_color=self.lightbutton)
self.countdown_complete.place(relx=0.5, rely=0.7, anchor=CENTER)
# I have a save function which saves some value as well as delete the window
# when number reaches 00:00:00, count up and update label to say its overdue
the problem is that after the complete button is pressed and the udf linked to the button deletes the window, the rest of the code continues to run.
i have a dict with elements inside, so if there is 1 element and when the only element is deleted, the lines referencing the array's crashes because it is now empty.
I need a way to stop count() from continuing after the complete button is pressed and window is deleted.
at least that's what I think the error is, here is the error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1921, in __call__
return self.func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 839, in callit
func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/customtkinter/windows/widgets/scaling/scaling_tracker.py", line 178, in check_dpi_scaling
if window.winfo_exists() and not window.state() == "iconic":
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1112, in winfo_exists
self.tk.call('winfo', 'exists', self._w))
_tkinter.TclError: can't invoke "winfo" command: application has been destroyed
invalid command name "4649351040_click_animation"
while executing
"4649351040_click_animation"
("after" script)
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1921, in __call__
return self.func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 839, in callit
func(*args)
File "/Users/tanhongen/Documents/GitHub/computing-coursework_S4-01/main.py", line 700, in countdown
self.countdownWindow.after(1000, self.countdown_time.configure(text=self.timer)) # updating the timer
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/customtkinter/windows/widgets/ctk_label.py", line 189, in configure
self._label.configure(text=self._text)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1675, in configure
return self._configure('configure', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1665, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!ctklabel2.!label"

python 2.7 : Tkinter ERROR: can't find package tile

I created GUI in Python (Python2.7) using Tkinter. I wish to have it up and running for both RHEL7.4 and RHEL5.11 versions. On REHL7.4, it works fine but on RHEL5.11, it gives the following error:
Traceback (most recent call last):
File "configure_workstation.py", line 28, in <module>
app = ConfigureWorkstation(wsObj)
File "/tmp/hnoman/v0.62/ConfigureWorkstation.py", line 90, in __init__
frame = F(self.fMenu, self)
File "/tmp/hnoman/v0.62/WorkstationInfoMenu.py", line 35, in __init__
self.generateHostnameFrame()
File "/tmp/hnoman/v0.62/WorkstationInfoMenu.py", line 50, in generateHostnameFrame
self.oLocation = ttk.OptionMenu(self.fHostname, self.location, dict[1], *dict.values())
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 1591, in __init__
Menubutton.__init__(self, master, **kw)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 797, in __init__
Widget.__init__(self, master, "ttk::menubutton", kw)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 554, in __init__
_load_tile(master)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 46, in _load_tile
master.tk.eval('package require tile') # TclError may be raised here
_tkinter.TclError: can't find package tile
Can someone guide how to overcome this?

pyimage2 does not exist error when I try to insert an image to window

I am trying to insert an image to window but I get an error.
Traceback (most recent call last):
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "C:\Users\Afro\Desktop\h.py", line 151, in start
pic_lab = Label(wind,image=pik)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2605, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2138, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist
Here's my code
wind = Tk()
name = money.jpg'
pik = ImageTk.PhotoImage(Image.open(name))
pic_lab = Label(wind,image=pik)
pic_lab.grid()
What do I need to do?
The string 'money.jpg' that is assigned to the variable name is missing a single quotation mark on the left.

Python - 'bgpic' Not Working

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.

_tkinter.TclError: unknown option "pyimage2"

I am trying to draw an image onto a canvas (mid conversion from place to canvas) and this error appears
hastebin containing code:
http://hastebin.com/tuciyisisa.py
Traceback (most recent call last):
File "D:\Stuff\python\Coursework\AQADo\main.py", line 82, in <module>
app = Application(master=root)
File "D:\Stuff\python\Coursework\AQADo\main.py", line 74, in __init__
self.drawCounter(space_y, current_space, game_canvas)
File "D:\Stuff\python\Coursework\AQADo\main.py", line 26, in drawCounter
canvas.create_image(170, space_y[current_space["1a"]], counter1)
File "C:\Python34\lib\tkinter\__init__.py", line 2291, in create_image
return self._create('image', args, kw)
File "C:\Python34\lib\tkinter\__init__.py", line 2282, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: unknown option "pyimage2"
canvas.create_image(170, space_y[current_space["1a"]], counter1)
There seems to be a problem with your function signature here. create_image expects a position tuple, plus keyword arguments. Try:
canvas.create_image((170, space_y[current_space["1a"]]), image=counter1)
Now your application runs without any apparent errors.

Categories