0

I know a cliche but I am trying to make a kanye quote app where it shows new Kanye quotes as shown below:


from tkinter import *
import requests


def get_quote():
    response = requests.get(url="https://api.kanye.rest")
    response.raise_for_status()
    data = response.json()
    quote = data["quote"]
    canvas.itemconfig(quote_text, text=quote)


window = Tk()
window.title("Kanye Says...")
window.config(padx=50, pady=50)

canvas = Canvas(width=300, height=414)
background_img = PhotoImage(file="background.png")
canvas.create_image(150, 207, image=background_img)
quote_text = canvas.create_text(150, 207, text="Kanye Quote Goes HERE", width=250, font=("Arial", 30, "bold"),
                                fill="black")
canvas.grid(row=0, column=0)

kanye_img = PhotoImage(file="kanye.png")
kanye_button = Button(image=kanye_img, highlightthickness=0, command=get_quote)
kanye_button.grid(row=1, column=0)

window.mainloop()

Every time I click but I am being told that the photo is not in my directiory even though it is in the same folder. I don't believe it's to do with the code but I've moved them out and then back in but it still won't work. Anyone else ever faced the issue and can help? Files It may be because the photos corrupted but I can open it on desktop.

Moved into different folders then back. Re-named it then tried again. I can't find the original photo online so I can't re download

TheJoeCa
  • 49
  • 7
  • Python doesn't look in "the same folder" - it looks in the _current working directory_ which may or may not be the same folder. – Bryan Oakley Dec 28 '22 at 20:51
  • If you have a look at the photo I am within my directory and folder. – TheJoeCa Dec 28 '22 at 20:52
  • I left this code the exact same (which I created about a month ago) and have now come back to it to make changes and it's no longer working – TheJoeCa Dec 28 '22 at 20:52
  • It is working for me. Try to provide full path to your files, e.g.: `c:\temp\kanye.png` – Alderven Dec 28 '22 at 20:58
  • This is from the 100 days of code course. I remembered doing this too. If you use `file="kanye.png"` you should have the .py file in the same folder, otherwise use the full path of the file. – RedNoyz Dec 28 '22 at 21:05
  • Yes it is from the course – TheJoeCa Dec 31 '22 at 17:46
  • I have tried around and I'm not sure what caused it previously but it is fully functioning as it was previously. – TheJoeCa Dec 31 '22 at 17:46

0 Answers0