开发者

Python/Tkinter: Building a toolbar that provides edit cut, copy, paste commands

开发者 https://www.devze.com 2023-01-24 05:56 出处:网络
I\'m looking for suggestions on how one might implement a toolbar that provides edit cut, copy, paste commands using the Tkinter framework. I understand how to build a toolbar and bind the toolbar com

I'm looking for suggestions on how one might implement a toolbar that provides edit cut, copy, paste commands using the Tkinter framework. I understand how to build a toolbar and bind the toolbar commands, but I'm confused over how the toolbar button bound commands will know which widget to apply the cut, copy, or paste action because the widget with edit activity will lose focus when the toolbar button is clicked. My first thought was to have each widget with potential edit activity set a global variable when the widget gains focus and have other widgets (without edit activity, eg. buttons, sliders, c开发者_开发知识库heckbox/radiobox, etc) clear this global variable. But this sounds complicated to maintain unless I build a framework of widgets that inherit this behavior.

Is there a simpler way to go about this or am I on the right track?


You don't have to maintain a big framework, you can create a single binding on the root widget for <FocusIn> and put all the logic in that binding. Or, use focus_class and bind to the class all.

Binding on the root will only affect children of the root, binding to all will affect all widgets in the entire app. That only matters if you have more than one toplevel widget.


You can tell the toolbar buttons to not take the focus; it's a configuration option and no UI guidelines I've ever seen have had toolbar buttons with focus. (Instead, the functionality is always available through some other keyboard-activatable mechanism, e.g., a hotkey combo.)

0

精彩评论

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