【发布时间】:2019-04-30 00:08:15
【问题描述】:
我已经有一组格式与下面类似的代码,并且似乎可以正常工作。但不知何故,这个图像没有弹出。它们与代码位于同一文件夹中。 Def small 是使图像正常工作的代码,而 def stripes 是给我一个错误的代码。
from tkinter import *
import tkinter as tk
from tkinter import ttk
def small():
s = Tk()
s.title('Small Preset Shirt (Not fit to scale)')
canvas = Canvas(s, width = 800, height = 100)
canvas.pack()
b1=ttk.Button(s,text='Click to Start', command = questions)
b1.pack()
photo = PhotoImage(file = 'small.png')
b1.config(image=photo,compound=RIGHT)
s.mainloop()
def stripes():
stripes = Tk()
stripes.title('Black Shirt with Stripes')
canvas = Canvas(stripes, width = 800, height = 100)
canvas.pack()
b2=ttk.Button(stripes,text='Click to See Final Price', command = final)
b2.pack()
photo = PhotoImage(file = 'stripes.png')
b2.config(image=photo,compound=RIGHT)
stripes.mainloop()
这是完整的回溯:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter /__init__.py", line 1705, in __call__
return self.func(*args)
File "/Users/Business/Documents/Python/small.py", line 159, in stripes
b2.config(image=photo,compound=RIGHT)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter. /__init__.py", line 1485, in configure
return self._configure('configure', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter. /__init__.py", line 1476, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist
【问题讨论】:
-
这两个函数是怎么调用的?您是否使用线程同时执行这两个功能?
标签: python-3.x tkinter tkinter-canvas ttk