Q:

Missing positional argument "pw_len" when generating password in tkinter

I am looking to generate a password in a new window (when a button is pressed) using tkinter with this code:
import math, random, os, string, tkinter, tkinter as tk

def generate_password(pass_len):
    symbols = "!$%^&*()-_=+QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"
    genpw = ''.join([symbols[math.floor(int(i) / 256 * len(symbols))] for i in os.urandom(pass_len)])    
    print(genpw)

create = tkinter.Button(root, pady=2, height=3, text = "create password", command = generate_password)

However, I encounter the following error:

TypeError: generate_password() missing 1 required positional argument: 'pass_len'

Any help is greatly appreciated.

A:

When you press the create password button, tkinter call your generate_password function without any argument and you function expect one.
Here a simple solution:
create = tkinter.Button(root, pady=2, height=3, text="create password", command= lambda: generate_password(10))

