首页 > 解决方案 > 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,text='Delete',command=lambda : S.pack_forget(),T.pack_forget())
    Delete.pack(side='right')


Create=Button(root,text='Create Boton',command=CreateButton)
Create.pack(side='left')

root.mainloop()

标签: pythontkintersyntax-errorkeywordkeyword-argument

解决方案


您必须在命令中输入“[]”才能使用多个命令。只需编辑它:

Delete=Button(root,text='Delete',command=lambda : S.pack_forget(),T.pack_forget())

至 :

Delete=Button(root,text='Delete',command=lambda : [S.pack_forget(),T.pack_forget()])

推荐阅读