【发布时间】:2020-04-27 17:08:21
【问题描述】:
我的代码有一些问题。我想制作一个后退按钮,但在显示窗口时出现错误。我的目标是制作一个目录,用户可以在其中按下一些按钮并与产品进行交互。但是当你按下按钮时,这个错误就会出现。
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/williamgranizo/.conda/envs/untitled/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/Users/williamgranizo/.conda/envs/untitled/lib/python3.7/site-packages/tkmacosx/basewidget.py", line 255, in cmd
self.unbind_class('button_command', '<ButtonRelease-1>')
File "/Users/williamgranizo/.conda/envs/untitled/lib/python3.7/site-packages/tkmacosx/basewidget.py", line 496, in unbind_class
bindtags = list(self.bindtags())
File "/Users/williamgranizo/.conda/envs/untitled/lib/python3.7/tkinter/__init__.py", line 1192, in bindtags
self.tk.call('bindtags', self._w))
_tkinter.TclError: bad window path name ".!toplevel2.!button6"
我不知道主要问题是什么,但主窗口似乎仍然可以工作。我的代码是:
def m1():
ventana.withdraw
modelo_1 = Toplevel()
modelo_1.title("Rose&Frites Hoodie con Gorra")
modelo_1.geometry("700x700")
modelo_1.configure(bg='black')
fn_1 = PhotoImage(file='mblac.png')
lblfn = Label(modelo_1, image=fn_1).place(x=0, y=0)
foto_1 = PhotoImage(file='mg_1.png')
nom_1 = Label(modelo_1, text ='Rose&Frites Hoodie con Gorra', fg ='black',
font=('Arial',20,'bold')).place(x=375,y=50)
myfoto_1 = Label(modelo_1, image=foto_1).place(x=50, y=30)
text_1 = Label(modelo_1, text= 'Promoción!! Hoodie de color negro\n con una estampa en forma de rosa. '
'\nTejido principal: 65%'
' algodón, 35% poliester.\nTejido secundario: 97% algodón, 3% elástico.'
'\n Gorra color amarillo con \n estampa de papas fritas.\n 97% algodón, 3% elástico'
'\n100% Hecho en Ecuador', bg='white', fg='black', font=('Arial', 16)).place(x=375, y=100)
tallas=Label(modelo_1,text="Tallas!",font=("Arial",16,'bold'),bg='white',fg='black').place(x=500,y=300)
xl = Button(modelo_1, text="XL",font=("Arial",9,"bold"),width=60,bg='black',fg='white').place(x=385,y=350)
l = Button(modelo_1, text="L",font=("Arial",9,"bold"),width=60,bg='black',fg='white').place(x=445,y=350)
m = Button(modelo_1, text="M",font=("Arial",9,"bold"),width=60,bg='black',fg='white').place(x=505,y=350)
s = Button(modelo_1, text='S',font=("Arial",9,'bold'),width=60,bg='black',fg='white').place(x=565,y=350)
xs = Button(modelo_1, text='XS',font=("Arial",9,'bold'),width=60,bg="black",fg="white").place(x=625,y=350)
precio = Label(modelo_1, text="$35.00", font=('Arial',15, 'bold')).place(x=50, y= 485)
cuidados=PhotoImage(file='cuidados.png')
cuidados1=Label(modelo_1,image=cuidados).place(x=375,y=400)
cuidados2=Label(modelo_1,text="Cuidados",font=("Arial",15,'bold')).place(x=500,y=505)
iva = Label(modelo_1,text='El precio no contiene I.V.A.', font=('Arial',14,'bold')).place(x=500,y=660)
back = Button(modelo_1, text='BACK!', font=('verdana', 14, 'bold'), fg='red',
command= modelo_1.destroy).place(x=0, y=0)
【问题讨论】:
-
您是否介意至少将部分代码分享给我们,如stackoverflow.com/help/how-to-ask 中所述?如果您与我们分享代码,请先阅读stackoverflow.com/help/minimal-reproducible-example
标签: python button tkinter back