Reputation: 19
Hi why does this program return the error? responseImagePath contains the exact file path of a local image. When i copy the print of responseImagePath directly into the PhotoImage, there is no such error. What am i doing wrong?
class Assistant():
def __init__(self, master):
self.label = ttk.Label(master)
self.label.pack()
self.button = Button(master, command = self.getResponse)
self.button.pack()
def getResponse(self):
message = assistant.message(
'89635700-591b-4f58-8345-409e08cef531',
session,
input={'text': 'picture'},
).get_result()
res = message["output"]["generic"][0]["text"]
print("Answer: " + res)
responseImagePath = message["output"]["generic"][1]["source"]
print("Response Image src: " + responseImagePath)
responseImage = PhotoImage(file = responseImagePath)
self.label.config(image = responseImage)
The print is -> Response Image src: r'C:\Users\Nathan\Desktop\test\resImage.gif' Error is -> _tkinter.TclError: couldn't open "r'C:\Users\Nathan\Desktop\test\resImage.gif'": no such file or directory
Upvotes: 0
Views: 417
Reputation: 385940
Take a close look at the error message, it is literally telling you the problem:
couldn't open "r'C:\Users\Nathan\Desktop\test\resImage.gif'": no such file or directory
It's telling you it is looking for a file where the first letter of the name is r
, followed by a single quote, followed by the letter C
, etc.
assistant.message(...).get_result()
appears to be returning an incorrect path with extra characters in it.
Upvotes: 2