Change global variable to value in entry field
<p>How can I change a global variable to a value inputted by a user in an entry field?</p>

<pre><code>card_no = 0

def cardget():
    global card_no
    card_no = e1.get()
    print(card_no)


def menu():
    global card_no
    root = Tk()

    e1 = Entry(root).pack()
    Label(root, text= "Enter card number").pack(anchor= NW)
    Button(root, text= "Confirm card", command=cardget).pack(anchor= NW)

menu()
</code></pre>

<p>You can pass the card no to the function called when the button is clicked:</p>

<pre><code>import tkinter as tk

def cardget(card_no):
    print(card_no)

def menu():
    root = tk.Tk()
    tk.Label(root, text="Enter card number").pack(anchor=tk.NW)
    e1 = tk.Entry(root)
    e1.pack()
    tk.Button(root, text="Confirm card", command=lambda *args: cardget(e1.get())).pack(anchor=tk.NW)
    root.mainloop()

menu()
</code></pre>

python tkinter