Python 如何从另一个模块访问事件处理程序函数?
我正在尝试制作一个应用程序,其中我有一个按钮,单击该按钮将调用一个函数。我想把这个函数放到主模块之外的另一个模块中。我将函数放在另一个模块中,并将其导入主模块,但我不知道如何绑定它 基本上,我想知道如何通过另一个主模块中定义的小部件访问模块中定义的函数。例如,在给定代码中,按钮在主模块中定义,但事件处理程序函数在另一个模块中定义。现在我想知道如何访问函数process\u事件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
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事件)