Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python tkinter中将事件和根添加到回调中?_Python_Python 3.x_Tkinter - Fatal编程技术网

如何在python tkinter中将事件和根添加到回调中?

如何在python tkinter中将事件和根添加到回调中?,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我正在使用tkinter创建一个基本应用程序,我想将gui的代码和函数及内容的代码拆分为不同的文件,但此函数: from tkinter import * from functions import * # this is my file I want to put my functions in # FUNCTIONS that needs root and event def callback(event): # my question is about this function

我正在使用tkinter创建一个基本应用程序,我想将gui的代码和函数及内容的代码拆分为不同的文件,但此函数:

from tkinter import *
from functions import * # this is my file I want to put my functions in

# FUNCTIONS that needs root and event
def callback(event): # my question is about this function
    root.after(50, select_all, event.widget)

# Setup
root = Tk()
(绑定)

因为我不知道如何通过比赛

长问题短问题,如何将事件和根传递到回调中?

您可以使用lambda:

def callback(event, root):
    root.after(50, select_all, event.widget)

...

edtLocation1.bind('<Control-a>', lambda e: callback(e, root))
def回调(事件,根): root.after(50,全选,event.widget) ... edtLocation1.bind(“”,lambda e:callback(e,root))
您不需要传入root。您可以从任何小部件调用
after
方法,传入的
事件
对象引用捕获事件的小部件

def callback(event):
    event.widget.after(50, select_all)
def callback(event, root):
    root.after(50, select_all, event.widget)

...

edtLocation1.bind('<Control-a>', lambda e: callback(e, root))
def callback(event):
    event.widget.after(50, select_all)