Python中“位置参数跟随关键字参数”错误

时间:2018-10-12 12:36:21

标签: python

我正在为一个像游戏《爆炸原子》这样的项目编写程序。但是,我在使按钮开始工作时遇到问题-退出的第一个按钮确实具有其应有的作用,但是我试图用第二个按钮调用子例程,但不能,因为当我将子例程作为命令放入时,出现错误“位置参数跟随关键字参数”。我不确定我写错了吗?这是代码:

button_1 = tkinter.Button(frame,text = 'QUIT', width = '6', height = '2',command=quit)
button_1.pack(side=LEFT)

button_2 = tkinter.Button(frame,text = 'START', width = '6', height = '2',gridimp(gridcreate,_switch,draw,CellGrid,draw,_eventCoords,handleMouseClick,handleMouseMotion))
button_2.pack(side=LEFT)

exat_window = tkinter.Tk()
exat_window.title('Exploding Atoms')
frame = Frame(exat_window )
frame.pack()

exat_window.mainloop()

1 个答案:

答案 0 :(得分:0)

在python中使用方法,您需要遵循定义它的方法签名。

首先输入位置参数,然后输入关键字映射参数。我觉得您的这一行有问题:

button_2 = tkinter.Button(frame,text = 'START', width = '6', height = '2', gridimp(gridcreate,_switch,draw,CellGrid,draw,_eventCoords,handleMouseClick,handleMouseMotion))

请问这是您的gridimp()在做什么的两个。

button_2 = tkinter.Button(frame, gridimp(gridcreate,_switch,draw,CellGrid,draw,_eventCoords,handleMouseClick,handleMouseMotion),text = 'START', width = '6', height = '2')

OR

button_2 = tkinter.Button(frame,text = 'START', width = '6', height = '2', command=gridimp(gridcreate,_switch,draw,CellGrid,draw,_eventCoords,handleMouseClick,handleMouseMotion))