开发者

'hover over' popup with Tkinter

开发者 https://www.devze.com 2023-01-27 16:58 出处:网络
I have implemented an informational popup in a python app using a Tkinter Menu widget.I have a Text widget on a canvas in the root window. I created a Menu widget that has root as its parent.When I de

I have implemented an informational popup in a python app using a Tkinter Menu widget. I have a Text widget on a canvas in the root window. I created a Menu widget that has root as its parent. When I detect a mouse hover over the text widget I post the popup menu with menuWidget.p开发者_运维技巧ost(). When I get a leave event from the text widget my intention was to have the popup disappear by calling menuWidget.unpost(), only the popup menu does not disappear until I click elsewhere outside the text widget.

First, is this a sane method for implementing an informational popup? And can anyone tell me why the popup menu won't disappear?


This is not the right way to do an informational popup. On the Mac and on windows machines menus are native controls. Because of this the unpost command doesn't work because tk cedes control to the system event loop in order to get platform-specific behavior.

What you want is to use instead is a toplevel window with the overrideredirect flag set. This lets you display a borderless window anywhere you want. The upside to this is that you aren't limited to simple text -- you can put anything you want in that toplevel -- another text widget, a canvas, buttons, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消