當前位置:股票大全官網 - 財經資訊 - python中報image "pyimage1" doesn't exist錯誤

python中報image "pyimage1" doesn't exist錯誤

a common reason for this is that you have multiple Tk instances in

your application.

if you create a PhotoImage under one Tk instance, you cannot access

it from other instances.

to fix this, make sure you only use one Tk instance (use Toplevel to create

new toplevel windows), or make sure that you create the image under the

same instance as the widget you're going to use it in. the easiest way to

do

this is to pass in a master keyword argument to the PhotoImage constructor:

photo = PhotoImage(..., master=myroot)

button = Button(myroot, ...)

button.photo = photo # keep a reference

對於PhotoImage對象只能在壹個線程下使用,在主要模塊中已經用TK()啟動壹個線程,再在次模塊中啟動壹個線程就不能調用PhotoImage對象。所以開啟希望開啟次窗口可采用用frame或者toplevel去代替。

以上屬於個人理解,錯誤望指點。