Retrieve/get back command callback function from TKinter widget

  callback, python, tkinter

I am (for some elaborate setup reasons) trying to retrieve the actual "command" callback function from TKinter widgets, for example setting up a callback for a button "b"

import tkinter as tk
root = tk.Tk()
b = tk.Button(root, text='btn', command=lambda:print('foo'))

both

b['command']
b.cget('command')

will only return a string like "2277504761920<lambda>" and not the actual command function. Is there a way to get the actual callback function?

Source: Python Questions

One Reply to “Retrieve/get back command callback function from TKinter widget”

LEAVE A COMMENT