Using Lambda or anonymous function. ; The command specifies a callback function that will be called automatically when the button clicked. menu = Menu (root) root.mainloop () Hi Windspar, Thanks for your input.But what I want is to return the input value to a variable in the main program so that I can use t for other purpose. By using the trace ("mode", lambda variable, variable: callback . In order to handle such events, we generally pass the defined function name as the value in the callback command. A button_name:button_object dictionary (Tkinter) 1 ; tkinter, create_rectangle 2 ; Tool to Convert SQL CE db to SQLITE DB 4 ; Control visual 3D object with Tkinter buttons 0 ; tkinter Python Calculator 5 ; Search for a Specified String in an Array 9 ; Tkinter Buttons 3 ; Tkinter question: button display 2 ; Troubling in double record datasorting 2 There are two ways to pass the argument to the tkinter button command . How to Pass Arguments to Tkinter button's callback Command? FunctionCall = Button (MainWindow, text='Enter', command=RandomFunction . Ideally I want the tkinter.button call to return the number entered so that I don't have to make use of the global. ; The text is the label of the button. ; Command callback. How to Bind Multiple Commands to Tkinter Button; Anyone a. dialog function return a result: answer = functions.dialog(.) We will create an event callback function by specifying the variable that stores the user input. this is the basic example of whats going on import tkinter as tk from time import sleep def getvalue (): value = "haha" sleep (3) return value def printvalue (): value = getvalue () print (value) app = tk.Tk () app.geometry ("500x300") button = tk.Button (app, text="print value", command=printvalue) button.pack () app.mainloop () "As for calling getString, it is in the button definition: button=Button(window,text='OK',command=partial(getString,window,string))" Ah, so it is, sorry I'm not used to looking for callbacks in tkinter functions and I missed that. We can get the value of any button in the Entry widget by defining the function which inserts the value in the Entry widget. For a particular event, we can also pass the argument to the function in the button's command. It means that you can assign the name of a function to the command option of the widget so that when the event occurs on the widget, the function will be called automatically. Actually my idea is to make one FTP GUI app so that user will provide input in GUI app & after the pressing Hit Me button the main program will be able to . Code language: Python (python) In this syntax: The container is the parent component on which you place the button. Using Partials. To use the command binding, you follow these steps: First . I am using the tkinter.button (see below) to enter some numbers into a variable. The gist of my code is like this: from tkinter import * def function (): root = Tk () entry = Entry (root) entry.pack () button = Button (root, text = "I'm a button", command = return entry.get ()) #Does not work, you can't do this in a callback button.pack () root.mainloop () What I'm trying to figure out is how to rewrite that return . First, you need to make your variable of a Tkinter string type like this: variable = StringVar () Your entry widget is fine, it's connected to the StringVar (). To get the value, we have to first define buttons having command for adding the specific value to be displayed on the Entry widget. Callback functions in Tkinter are generally used to handle a specific event happening in a widget. In Tkinter, some widgets allow you to associate a callback function with an event using the command binding. How to Get Value From Entry On Button Click in Tkinter . The command option associates the button's action with a function or a method of a class. To update the Entry widget, we can delete the previous value using delete (0, END) method. I am trying to code without using globals. The time between the creation of the Button, and the line after that where you assign filepath, is about a thousandth of a second.The user would have to have very fast reflexes to navigate through the open file dialog in that small window of opportunity :-) I'm oversimplifying somewhat, but the point of my joke is, don't rely on user input being present at any line before mainloop. Stack Overflow - Where Developers Learn, Share, & Build Careers We can add an event callback function to the Entry widget whenever it gets modified. Your button doesn't need lambda, though, because you don't need to pass an argument to your RandomFunction (). January 14, 2022 January 14, 2022 amine.kouis 0 Comments entry get tkinter not working, entry tkinter, .