在Python中,我想回到主窗口的后退按钮。

问题描述 投票:0回答:1

我的代码有一些问题。我想做一个后退按钮,但当我显示窗口时出现了错误。我的目标是做一个目录,用户可以在其中按下一些按钮,并与产品互动。但是当你按下按钮的时候,这个错误就出来了。

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)
python button tkinter back
1个回答
1
投票

错误 _tkinter.TclError: bad window path name 当您使用 tkmacosx 销毁任何窗口时触发。Button. 这个问题已经在最新的更新中得到了解决。tkmacosx (0.1.3).

用pip更新包,应该可以解决这个错误。

pip install tkmacosx --upgrade

pip install tkmacosx==0.1.3
© www.soinside.com 2019 - 2024. All rights reserved.