0

Hey so I've made this error handler, it'd be ran if 2 specific buttons were enabled. The code:

def thirderror():
  error2 = Toplevel()
  error2.geometry("250x200")
  error2.configure(bg = "#ffffff")
  canvas2 = Canvas(
      error2,
      bg = "#ffffff",
      height = 200,
      width = 250,
      bd = 0,
      highlightthickness = 0,
      relief = "ridge")
  canvas2.place(x = 0, y = 0)

  errorimg1_resp = requests.get("https://i.postimg.cc/jS8zFCc6/error0.png")
  errorimg1 = ImageTk.PhotoImage(Image.open(BytesIO(errorimg1_resp.content)))
  errorb1 = Button(
      error2,
      image = errorimg1,
      borderwidth = 0,
      highlightthickness = 0,
      command = error2.destroy,
      relief = "flat")

  errorb1.place(
      x = 0, y = 155,
      width = 250,
      height = 45)

  backgroundimg3_resp = requests.get("https://i.postimg.cc/VNVPyTW0/background.png")
  background_img3 = ImageTk.PhotoImage(Image.open(BytesIO(backgroundimg3_resp.content)))
  background3 = canvas2.create_image(
      125.0, 63.0,
      image=background_img3)
  error2.resizable(False, False)

For some reason right after it shows, the images (Background and button) disappear. Also I'm using a link to show the images because I want to convert it to an exe later and not have to have the images in the same directory.

Anyways, how do I fix the images?

  • the links could get unusable after a while, if you don't want files in the same directory you can add them later directly to the exe – Matiiss Sep 28 '21 at 14:53
  • 2
    Does this answer your question? [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function) – Matiiss Sep 28 '21 at 14:54
  • @Matiss I don't know how to add them directly to the exe. Also, I don't think that website deletes images automatically. And I'm using other links with other error handlers with the same code but different variable names and links and they work like a charm. – PeterProfits Sep 28 '21 at 14:56
  • @Matiiss Thanks for linking that post, it helped me. – PeterProfits Sep 28 '21 at 15:09

0 Answers0