开发者

Creating text buttons in wxPython

In my application I want to create buttons, minus the whole button part. Like clicking a URL, I guess, with some basic functionality like a subtle change in color or style upon hover/click.

I've accomplished this so far with wx.StaticText, but my problem is in getting a left click event to be recognized. Here's the relevant code:

self.text = wx.StaticText(self.ba开发者_Python百科ckground, -1, 'Text test')
self.text.Bind(wx.EVT_COMMAND_LEFT_CLICK, self.DoSomething)

It just doesn't have any effect at all. Any ideas or alternatives?

edit: Got it. Should have called wx.EVT_LEFT_UP.


PlateButtons (wx.lib.platebtn) will give you a lot of control over the buttons, including a "flat" button (with no border), and mouse over color changes, etc. (There is also style=wx.NO_BORDER for a regular button, but this isn't reliable on Macs.)

Depending on what you want to do, it's probably better to use a button than StaticText since there are a lot of issues like focus, sizing, disabling, changing image on click, etc, which are less noticed but still expected and/or useful in buttons. There are a number of examples of Python code which creates buttons, including PlateButtons and GenericButtons, where you can see what's involved in making a good button. It's not impossible, but a hassle if you don't need to do it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜