gpt4 book ai didi

python - Tkinter-SyntaxError : non-keyword arg after keyword arg

转载 作者:行者123 更新时间:2023-12-03 08:34:13 24 4
gpt4 key购买 nike

我有一个我无法理解的问题,因此在删除按钮中,尝试在创建按钮后将其删除的地方,出现以下错误:

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()

最佳答案

您必须在命令中放置“[]”才能访问使用多个命令。
只需从中进行编辑:

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()])

关于python - Tkinter-SyntaxError : non-keyword arg after keyword arg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63455403/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com