2 pièce(s) jointe(s)
Problème d'ouverture d'un fichier GIF
Bonjour,
Le code ci après provient du livre "Python and Tkinter programming (example_8_12.py) de John Grayson;
Il est exécuté sous Windows 10 avec un environnement Python 3.7.3 et Anaconda3.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
from tkinter import*
import sys, string
class MakeImageMap:
def __init__(self, master, file=None):
self.root=master
self.file=file
self.img=PhotoImage(file=File) # version 1
self.img= imageTk.PhotoImage(Image, open(file) # version 2
self.width=self.img.width()
self.height=self.image.height()
self.canvas=Canvas(self.root, width=self.width, height=self.height
self.canvas.pack(side="top", fill=BOTH, expand='no')
self.canvas.create_image(0, 0, anchor=NW, image=self.img
if __name__ == '__main__':
file = "F:\OneDrive\Visual Studio 20129\Source\Python Lib\Grayson\Chapter08\Example_8_12\calculator.gif"
root = Tk()
makeImageMap = MakeImageMap(root, file=file)
makeImageMap.root.mainloop() |
Le problème se produit lors de l'appel à MakeImageMap(root, file=file)
Dans la version 1, on aboutit à
...\Anaconda3\Lib\tkinter\__init__ line 3501
self.tk.call(('image', 'create', 'imgtype' , name) + options)
qui cause le message;
_tkinter.TclError: couldn't open "calculator.gif": permission denied.
Dans la version 2 on aboutit à:
...\Anaconda3\Lib\site-packages\PIL\Image.py line 2609
fp=__builtins__.open(filename, "rb")
qui produit l'erreur
Permission error- Permission denied F:\...\calculator.gif
Dans la version 2, j'ai essayé, sans succès, les combinaisons suivantes d'attributs,
pensant que le problème pourrait venir de là:
attributs calculator.gif /attribut de open-filename, attribut) de Anaconda3
"ax" / "rb"
"a" / "rb"
"r" / "rb"
"r" / "r"
J'ai également essayé avec un fichier Png, avec le même résultat.
Les fichiers étaient la propriété de l'administrateur avec la permission "control total" pour celui ci.