- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Passing arguments to a Tkinter button command
The Button widget in Tkinter is generally used for pushing an event defined in an application. We can bind the events with buttons that allow them to execute and run whenever an action is triggered by the user.
However, sharing the data and variables outside the function and events seems difficult sometimes. With the Button widget, we can pass arguments and data that allows the user to share and execute the event.
In general, passing the arguments to a button widget allows the event to pick the arguments and use them further in the program.
Example
# Import the required library from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x250") # Define a function to update the entry widget def update_name(name): entry.insert(END, ""+str(name)) # Create an entry widget entry=Entry(win, width=35, font=('Calibri 15')) entry.pack() b=ttk.Button(win, text="Insert", command=lambda:update_name("Tutorialspoint")) b.pack(pady=30) win.mainloop()
Output
Running the above code will display a window with an Entry widget and a button to insert text in it.
Click the button "Insert" to add text in the Entry widget.
- Related Articles
- How to pass arguments to a Button command in Tkinter?
- How can I pass arguments to Tkinter button's callback command?
- Change command Method for Tkinter Button in Python
- Passing Arguments to a Subroutine in Perl
- Java command line arguments
- Passing unknown number of arguments to a function in Javascript
- Command Line Arguments in Python
- Command line arguments in Java
- Command Line arguments in C#
- Explain Java command line arguments.
- Command Line arguments in Lua
- Tkinter binding a function with arguments to a widget
- How to create a Tkinter toggle button?
- How to pass command line arguments to a python Docker container?
- How to Parse Command Line Arguments in C++?

Advertisements