WxPython改变位图按钮的形状
嗨,我对 wxPython 还算陌生,仍在学习过程中。我正在尝试使用特定图像制作位图按钮,例如: http://i.min .us/idk3Uy.png
问题是我想保留按钮中图像的原始形状,例如圆形按钮而不是矩形按钮(默认情况下)。
我想知道到底如何做到这一点,或者是否有可能做到这一点;我确实查看了文档,发现样式常量 wx.BU_EXACTFIT 删除了不必要的边框......但它仍然不是我想要的理想形状。
谢谢。
Hi I'm sort new to wxPython and still in the process of learning. I'm trying to make a bitmap button using a particular image like this for example: http://i.min.us/idk3Uy.png
The catch is I want to retain the original shape of the image in the button, like a circular button for example instead of a rectangular one (which is default).
I want to know how to do that exactly or if it is possible to do that at all; I did take a look at the documentation and I've found the style constant wx.BU_EXACTFIT removes the unnecessary borders...but it's still not in the desirable shape that I want it to be.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能必须为此实现自定义控件。我已经完成了相当多的自定义 wxPython 控件,因此我继续为您编写了一个
ShapedButton
类。 =)要运行此演示,您只需要三个图像:
这三个图像的使用取决于按钮的状态。仅需要“正常”,但您可能至少希望提供“正常”和“按下”,以便用户在单击时获得反馈。
该控件仅响应普通位图的非透明区域中的单击。单击并释放时,它会正确触发
EVT_BUTTON
事件。享受!
You're probably going to have to implement a custom control for this. I've done my fair share of custom wxPython controls, so I went ahead and wrote a
ShapedButton
class for you. =)To run this demo, you just need three images:
The three images are used depending on the state of the button. Only the "normal" one is required, but you probably want to at least provide "normal" and "pressed" so the user gets feedback when clicking.
The control only responds to clicks in non-transparent areas of the normal bitmap. It properly fires the
EVT_BUTTON
event when clicked and released.Enjoy!