如何在python tkinter中将事件和根添加到回调中?
我正在使用tkinter创建一个基本应用程序,我想将gui的代码和函数及内容的代码拆分为不同的文件,但此函数:如何在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
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)