_tkinter.TclError:图像“ pyimage9”不存在

时间:2019-10-02 11:37:01

标签: tkinter python-3.6

我知道这个问题已经被问过几次了,但是经过如此多的研究,我仍然无法解决。当我执行单个文件时,我的代码运行良好,但是当我将此Calibration.py文件导入其他title.py文件时,出现此错误。谁能帮我。谢谢。

from __future__ import division
import os
import sys
from tkinter import *
from tkinter import filedialog
import cv2
from PIL import ImageTk, Image
import numpy as np

class Calibration:
    def __init__(self,master):
        self.master=master
        master.title(" Pol Calibration")
        master.geometry('670x600')

        master.resizable(0,0)
        master.wm_iconbitmap(r"F:\MyCode\Customized_Logo.ico")

        #add image on Button

        file = Image.open(r"F:\MyCode\file3.jpg")
        resized_file = file.resize((25, 20),Image.ANTIALIAS)
        file = ImageTk.PhotoImage(resized_file)


        btn_rh = Button(master,image=file)
        btn_rh.image=file
        btn_rh.place(x=20,y=50)

def run_calibration():
    root= Tk()
    my_gui = Calibration(root)
    root.mainloop()

run_calibration()

此Calibration.py文件单独处于罚款状态

def event_calibration():
    from calibration import run_calibration
    run_calibration()



compact = Menubutton ( root, text=" Compact-Pol/Hybrid-PolSAR Data Calibration ", 
    relief=RAISED,fg="black",bg="peach puff" ,activeforeground="black",activebackground="peach puff")
compact.menu =  Menu ( compact, tearoff = 0,relief=RAISED,fg="black",bg="peach puff")
compact["menu"] =  compact.menu

compact.menu.add_command( label=" Right Circular Transmit And Linear Receive  ",command=event_calibration)

compact.config(font=('Helvetica 11'))
compact.place(x=250,y=60)

**当我尝试通过导入title.py来在此处执行Calibration.py文件时,出现此错误。我在使用PhotoImage时遇到同样的问题*

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
        return self.func(*args)
  File "F:\MyCode\title.py", line 71, in calibration
  from calibration import run_calibration
  File "F:\MyCode\calibration.py", line 361, in <module>
  run_calibration()
  File "F:\MyCode\calibration.py", line 358, in run_calibration
      my_gui = Calibration(root)
  File "F:\MyCode\calibration.py", line 321, in __init__
      btn_rh = Button(master,image=file)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2366, in __init__
  Widget.__init__(self, master, 'button', cnf, kw)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2296, in __init__
      (widgetName, self._w) + extra + self._options(cnf))
  _tkinter.TclError: image "pyimage9" doesn't exist

0 个答案:

没有答案