简体   繁体   English

如何将鼠标单击绑定到 Tkinter 中所有 windows 中的函数

[英]How to bind mouse clicks to functions in all windows in Tkinter

I am trying to bind the middle mouse click to a function:我正在尝试将鼠标中键单击绑定到 function:

root = Tk() 

def leftclick(self):
    print("Yep!")

root.bind("<Button-2>", leftclick)
root.mainloop()

This works, however only on the Tkinter window, any ideas for other windows?这有效,但仅适用于 Tkinter window,对其他 windows 有什么想法吗?

Tkinter has no support for what you ask. Tkinter 不支持您的要求。 Tkinter can only bind functions to windows that it creates. Tkinter 只能将函数绑定到它创建的 windows。 If you want to bind functions to events in other windows you'll have to use some platform-specific third-party library.如果要将函数绑定到其他 windows 中的事件,则必须使用一些特定于平台的第三方库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM