Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Code gives missing 1 required positional argument error

This code gives the error:

TypeError: otsi() missing 1 required positional argument: 'x'

The code is supposed to open a .pdf file by a part of its name, which I input to the Tellimus_entry.

Tellimus_entry = Entry(ws)
Tellimus_entry.grid(row=4,column=3,padx=(10, 10), sticky=(N, S, E, W), columnspan=3)


def otsi(x):
    return glob.glob(f'C:/Users/ASUS/Desktop/Proov/*{x}*.pdf')

    otsitav = Tellimus_entry.get()
    files = otsi(otsitav)
    print(files)
    if files:
        os.startfile(files[0])
nupp = ttk.Button(ws, text="Ava tellimuse PDF", command=otsi)
nupp.grid(row=3,column=3, sticky=(N, S, E, W), pady=5, padx=5)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can pass the command argument as a lambda, this way the x parameter you need wont be missing

Tellimus_entry = Entry(ws)
Tellimus_entry.grid(row=4,column=3,padx=(10, 10), sticky=(N, S, E, W), columnspan=3)


def otsi(x):
    return glob.glob(f'C:/Users/ASUS/Desktop/Proov/*{x}*.pdf')

    otsitav = Tellimus_entry.get()
    files = otsi(otsitav)
    print(files)
    if files:
        os.startfile(files[0])
nupp = ttk.Button(ws, text="Ava tellimuse PDF", command=lambda: otsi(whatever_param_you_need))
nupp.grid(row=3,column=3, sticky=(N, S, E, W), pady=5, padx=5)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading