[英]ERROR IN PYTHON Positional argument follows keyword argument
我試圖使用tkinter
在python中使用許多命令創建按鈕,但是當我嘗試編譯它們時給我一個錯誤:
位置參數跟在關鍵字參數之后
c = Button(WPEngine ,text="Start", command=doStuff, command=callback, command=start)
c.grid(row=1,column=1)
您收到的錯誤:
位置參數跟在關鍵字參數之后
但是該錯誤與重復的關鍵字參數無關。 我本來希望看到此錯誤:
SyntaxError:關鍵字參數重復
因此,我懷疑您的代碼中還有其他問題,但是我們需要查看更多代碼才能確定根本原因。
除了調用多個命令之外,您還可以執行2種方法之一。
第一種方法只是調用一個函數,然后再調用其他幾個函數。
代碼示例 :
from tkinter import *
def do_stuff():
print('doStuff')
def callback():
print('callback')
def start():
print('start')
def do_multiple_things():
do_stuff()
callback()
start()
root = Tk()
c = Button(root, text="Start", command=(do_stuff, callback))
c.grid(row=1, column=1)
root.mainloop()
第二種方法是使用lambda調用列表/元組中的多個函數。
代碼示例 :
from tkinter import *
def do_stuff():
print('doStuff')
def callback():
print('callback')
def start():
print('start')
root = Tk()
c = Button(root, text="Start", command=lambda: (do_stuff(), callback(), start()))
c.grid(row=1, column=1)
root.mainloop()
c = Button(WPEngine ,text="Start", command=doStuff, command=callback, command=start)
您正在將多個command
參數傳遞給Button
構造函數。 要解決此問題,請確定要在command
參數中傳遞哪個函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.