#๐Ÿ”’ tkinter file problem

13 messages ยท Page 1 of 1 (latest)

sick pecanBOT
#

@shadow mauve

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

shadow mauve
#

code : import tkinter as tk
def legostore():
btnme.grid_forget()
btnd.grid_forget()
btnl.grid_forget()
btnn.grid_forget()
imagelm = tk.PhotoImage(file=r"C:\Users\ckgun\Downloads\klockilegominecraft.jpg")
resizedlm_image = imagelm.subsample(2)
btnlegominecraft = tk.Button(root, image=resizedlm_image, width=100, height=50)
btnlegominecraft.grid(row=0, column=0, padx=10, pady=10)

root = tk.Tk()
root.geometry("700x700")

imagel = tk.PhotoImage(file=r"C:\Users\ckgun\Downloads\lego.png")
resizedl_image = imagel.subsample(2)
btnl = tk.Button(root, image=resizedl_image, width=100, height=100, command=legostore)
btnl.grid(row=0, column=1, padx=10, pady=10)

imageme = tk.PhotoImage(file=r"C:\Users\ckgun\Downloads\mediaexpert.png")
resizedme_image = imageme.subsample(2)
btnme = tk.Button(root, image=resizedme_image, width=100, height=50)
btnme.grid(row=0, column=0, padx=10, pady=10)

imaged = tk.PhotoImage(file=r"C:\Users\ckgun\Downloads\decathlon.png")
resizedd_image = imaged.subsample(2)
btnd = tk.Button(root, image=resizedd_image, width=200, height=50)
btnd.grid(row=0, column=2, padx=10, pady=10)

imagen = tk.PhotoImage(file=r"C:\Users\ckgun\Downloads\nike.png")
resizedn_image = imagen.subsample(2)
btnn = tk.Button(root, image=resizedn_image, width=100, height=80)
btnn.grid(row=0, column=3, padx=10, pady=10)

root.mainloop()

#

Error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ckgun\AppData\Local\Programs\Python\Python312\Lib\tkinter_init_.py", line 1967, in call
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:\Users\ckgun\OneDrive\Pulpit\sklep.py", line 7, in legostore
imagelm = tk.PhotoImage(file=r"C:\Users\ckgun\Downloads\klockilegominecraft.jpg")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ckgun\AppData\Local\Programs\Python\Python312\Lib\tkinter_init_.py", line 4146, in init
Image.init(self, 'photo', name, cnf, master, **kw)
File "C:\Users\ckgun\AppData\Local\Programs\Python\Python312\Lib\tkinter_init_.py", line 4093, in init
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "C:\Users\ckgun\Downloads\klockilegominecraft.jpg"

lapis kettle
shadow mauve
#

really

shadow mauve
lapis kettle
#

you would have to use ImageTk

shadow mauve
#

i know

#

ok thanks

sick pecanBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ tkinter file problem