Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 如何从另一个模块访问事件处理程序函数?_Python_User Interface_Tkinter_Event Handling - Fatal编程技术网

Python 如何从另一个模块访问事件处理程序函数?

Python 如何从另一个模块访问事件处理程序函数?,python,user-interface,tkinter,event-handling,Python,User Interface,Tkinter,Event Handling,我正在尝试制作一个应用程序,其中我有一个按钮,单击该按钮将调用一个函数。我想把这个函数放到主模块之外的另一个模块中。我将函数放在另一个模块中,并将其导入主模块,但我不知道如何绑定它 基本上,我想知道如何通过另一个主模块中定义的小部件访问模块中定义的函数。例如,在给定代码中,按钮在主模块中定义,但事件处理程序函数在另一个模块中定义。现在我想知道如何访问函数process\u事件 main模块.py my_button = tk.Button(application_window, text=&qu

我正在尝试制作一个应用程序,其中我有一个按钮,单击该按钮将调用一个函数。我想把这个函数放到主模块之外的另一个模块中。我将函数放在另一个模块中,并将其导入主模块,但我不知道如何绑定它

基本上,我想知道如何通过另一个主模块中定义的小部件访问模块中定义的函数。例如,在给定代码中,按钮在主模块中定义,但事件处理程序函数在另一个模块中定义。现在我想知道如何访问函数process\u事件


main模块.py

my_button = tk.Button(application_window, text="Example")
my_button.bind("<Enter>", process_event)
def process_event(event):
       print("The process_event function was called.")
import AmotherModule 

my_button.bind("<Enter>", AmotherModule.process_event)

main模块.py

my_button = tk.Button(application_window, text="Example")
my_button.bind("<Enter>", process_event)
def process_event(event):
       print("The process_event function was called.")
import AmotherModule 

my_button.bind("<Enter>", AmotherModule.process_event)
导入模块
my_button.bind(“,AmotherModule.process_事件)

将AmotherModule作为am导入
my_button.bind(“,am.process_事件)

来自AmotherModule导入过程\u事件
my_button.bind(“,process_事件)

导入AmotherModule
绑定(…,AmotherModule.process\u事件)