Passing argument to Tkinter button command

import tkinter as tk
def on_button_click(entry_text):
    print(f"The argument passed is: {entry_text}")
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="Submit", command=lambda: on_button_click(entry.get()))
button.pack()
root.mainloop()

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top