R
R
Roma Kotolup2021-03-24 12:33:46
Python
Roma Kotolup, 2021-03-24 12:33:46

How to load a label as an image in python tkinter?

How to load a label as an image in python tkinter?
I created a label like this:

the code

import os, winshell
from win32com.client import Dispatch
# Соединяем пути, с учётом разных операционок.
path = os.path.join("C:\Fox.lnk")
 # Задаём путь к файлу, к которому делаем ярлык.
target = 'C:\cer.gif'
 # Назначаем путь к рабочей папке.
 wDir = r"C:\\Users\\"
shell = Dispatch('WScript.Shell')
# Создаём ярлык.
shortcut = shell.CreateShortCut(path)
# Путь к файлу, к которому делаем ярлык.
shortcut.Targetpath = target
# Путь к рабочей папке.
shortcut.WorkingDirectory = wDi
# Обязательное действо, сохраняем ярлык.
shortcut.save()


and then I load it into a PhotoImage and render it in a Label:
error

Traceback (most recent call last):
File "C:\red.pyw", line 5, in
my_image = PhotoImage(file="C:\Fox.lnk")
File "C:\Users\Oksana\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 4063, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Oksana\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 4008, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "C:\Fox.lnk"


How to fix it?
or at least just through a shortcut to find out where this file is and download it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-03-24
@roma2

Che? What do you want to do more? A shortcut in Windows is a file containing a structure that contains the path to the file that the shortcut refers to and other data (path to the icon, description, hint). What do you want to do when you pass a non
-image file to PhotoImage ? In order to load the file referenced by the shortcut into PhotoImage, on the contrary, you need to read the shortcut and get the path to the file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question