我希望在执行与图像相关的命令时,图像会出现,但我得到的是,当执行与图像相关的不同命令时,图像会保留在那里,并且感觉有点松散的重叠
这是密码
from tkinter import *
from PIL import ImageTk,Image
w=Tk()
w.geometry('800x400')
nam=Label(w,text="name of car")
nam.place(x=130,y=50)
w.configure(bg='#b000ff')
le2=Label(w,text="NUMBER",bg='#6863f6',fg='black',font='comicsansms 10 bold')le2.place(x=0,y=180)
ent2=Entry(w,textvar=StringVar,bg='white',fg='black')
ent2.place(x=70,y=180)
lo = Image.open('F:\\all net downoades\\audier.png')
vo = ImageTk.PhotoImage(lo)
lo4 = Image.open('F:\\all net downoades\\lambo.png')
vo2 = ImageTk.PhotoImage(lo4)
def one():
cn = Canvas(w, widt=400, height=250) # n, ne, e, se, s, sw, w, nw, or center
cn.pack(side=BOTTOM, anchor=E)
cn.create_image(200,135,image=vo)
#another func
def two():
cn6 = Canvas(w, widt=400, height=250) # n, ne, e, se, s, sw, w, nw, or center
cn6.pack(side=BOTTOM, anchor=E)
cn6.create_image(200,135,image=vo2)
def both():
if int(ent2.get()) == 1:
one()
elif int(ent2.get()) == 2:
two()
else:
pass
bui=Button(w,text="ok",command=both)
bui.place(x=0,y=100)
w.mainloop()
无论何时调用
one()
或two()
,都不应创建新画布。您应该创建画布一次并将其隐藏,然后更新画布内的图像并在one()
或two()
函数内显示:试试这样,让我知道
相关问题 更多 >
编程相关推荐