如何解决Tkinter-SyntaxError:关键字arg之后为非关键字arg
我有一个无法理解的问题,因此在删除按钮中创建按钮后尝试删除按钮的地方,出现此错误:
Delete=Button(root,text='Delete',command=lambda : S.pack_forget(),T.pack_forget())
SyntaxError: non-keyword arg after keyword arg
代码:
from Tkinter import *
root=Tk()
Menubar = Menu(root)
root.config(menu=Menubar)
def CreateButton():
S=Button(root,text='Second Boton')
S.pack(side='right')
T=Button(root,text='Third Boton')
T.pack(side='right')
Delete=Button(root,T.pack_forget())
Delete.pack(side='right')
Create=Button(root,text='Create Boton',command=CreateButton)
Create.pack(side='left')
root.mainloop()
解决方法
您必须在命令中放置“ []”才能访问使用多个命令。 只需从中进行编辑即可:
Delete=Button(root,text='Delete',command=lambda : S.pack_forget(),T.pack_forget())
收件人:
Delete=Button(root,command=lambda : [S.pack_forget(),T.pack_forget()])