[Python] Can't use get() when trying to pull value from Entry() widget - Tkinter

Discussão em 'Python' iniciado por Stack, Janeiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    Not sure where I'm going wrong here. Tkinter is imported, yet get() does not work. Am I missing something? Just trying to get the int value that was passed into the Entry widget.

    import random
    import string
    from tkinter import *

    def generate_password(length):
    characters = string.ascii_letters + string.digits + string.punctuation
    password = ''.join(random.choice(characters) for _ in range(length))
    return password

    root = Tk()
    root.title("PASSWORD GENERATOR")
    root.geometry("450x400")
    int_ans_var = IntVar()
    title = Label(root, text="RoosSec Password Generator", font=("bold", 16), fg = "Black", bg="#228B22").pack()
    input_num = Label(root, text="Password length: ", font=("bold", 12), fg = "Black", bg="#228B22").place(x=100, y=150)
    num_box = Entry(root, font=("bold", 14), width=10, fg= "Black", bg="White", justify=LEFT).place(x=230, y=150)
    int_ans_var = num_box.get()
    btn = Button(root, text="Generate Password", fg="white", bg="black", height="2", width="15", command=generate_password).place(x=300, y=350)
    root.mainloop()

    Continue reading...

Compartilhe esta Página