如何用我自己的行为重新创建 TextField 小部件?
我想使用 PyGTK 创建一个测试应用程序。
我的目标是创建一个 100% 定制的文本字段小部件。事实上,我想完全改变文本字段小部件的默认行为。
是否可以完全更改文本字段的行为(如快捷键/键盘映射、滚动行为等)?
是否可以从头开始重新创建小部件?如果是,我该怎么做?
谢谢。
I would like to create a test application with PyGTK.
My goal is to create a textfield widget 100% customized. Indeed, I would like to fully change the default behavior of a textfield widget.
Is it possible to fully change the behavior of a textfield (like shortcuts/keymaps, scroll behavior, etc.) ?
Is it possible to recreate the widget from scratch ? If yes, how can I do that ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您指的是 gtk.Entry 还是 gtk.TextView?
无论如何,您都需要对要自定义的小部件进行子类化,并覆盖您需要更改的任何方法。如果您可以阅读 C 代码,那将会很有帮助,因为您可以查看小部件源代码。如果您从未编写过自己的小部件,您可能需要从像 http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
Are you referring to a gtk.Entry or a gtk.TextView?
In any case, you are going to want to subclass the widget you want to customize and override any methods that you need to change. If you can read C code, that would be helpful as you can look over the widget source code. If you've never written your own widgets, you might want to start with a tutorial like http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
不要从头开始重新创建它。相反,从中派生并超载您想要更改的内容。
Don't recreate it from scratch. Derive from it instead and overload what you intend to change.