import tkinter as tk from idlelib.configdialog import ConfigDialog from idlelib import macosx class FunkyPatch: def __init__(self, target_exp, replace_exp, locals): self.target_exp = target_exp self.replace_exp = replace_exp self.locals = locals def __enter__(self): self.target = eval(self.target_exp, {}, self.locals) self.replace = eval(self.replace_exp, {}, self.locals) exec(self.target_exp + ' = ' + self.replace_exp, {}, self.locals) self.replace.func = self.target # So replace can call target return self.target, self.replace def __exit__(self, et, ev, tr): tarname = '_target_func_' self.locals[tarname] = self.target exec(self.target_exp + ' = ' + tarname, self.locals) del self.locals[tarname] del self.replace.func def wrapsetup(self, master, cnf): wrapsetup.func(self, master, cnf) print(self.widgetName, self._w) def wrapCPFT(self, locals=locals()): with FunkyPatch('tk.BaseWidget._setup', 'wrapsetup', locals): wrapCPFT.func(self) root = tk.Tk() macosx._initializeTkVariantTests(root) with FunkyPatch('ConfigDialog.CreatePageFontTab', 'wrapCPFT', locals()): ConfigDialog(root) #print('Setup func is now ', tk.BaseWidget._setup.__name__)