简体   繁体   中英

ERROR IN PYTHON Positional argument follows keyword argument

I tried to make a button with many command in python using tkinter but when i try to compile they give me a error:

Positional argument follows keyword argument

    c = Button(WPEngine ,text="Start", command=doStuff, command=callback, command=start)
    c.grid(row=1,column=1)

The error you got:

Positional argument follows keyword argument

But that error is not related to repeated keyword arguments. I would have expected to see this error instead:

SyntaxError: keyword argument repeated

Because of this I suspect you have something else going on in your code but we would need to see more code to be sure of the root cause.

That aside to call multiple commands you can do this 1 of 2 ways.

1st method is simply call a single function that then calls several other functions.

Code example :

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

2nd method is to use a lambda to call multiple functions in a list/tuple.

Code Example :

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)

You were passing multiple command arguments to Button constructor. To fix this - decide which function are you passing in the command argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM