wx.lib.buttons
虽然按钮可能有点简单。
然而,正如@RobinDunn指出的,他应该知道,因为版本2.9.1 wx。按钮支持显示文本和图像(当前仅当使用wxMSW、wxGTK或OSX/Cocoa端口时)。
desktop settings
我已经准备好了
Show Icons on Buttons
或者第二种方法使用
wx.Button
使用第二种方法,按钮看起来更好,失去了平面外观。
import wx
import wx.lib.buttons as buts
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
pause_button = buts.GenBitmapTextButton(self, -1, bitmap=wx.Bitmap("pause.png"), label= "Pause")
play_button = buts.GenBitmapTextButton(self, -1, bitmap=wx.Bitmap("play.png"), label= "Play")
time_button = wx.Button(self, -1, label= "Time")
time_button.SetBitmap(wx.Bitmap("toggle1.png"),wx.RIGHT)
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(pause_button, 0, wx.CENTER | wx.ALL,10)
box.Add(play_button, 0, wx.CENTER | wx.ALL,10)
box.Add(time_button, 0, wx.CENTER | wx.ALL,10)
self.SetSizerAndFit(box)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
pause_button.Bind(wx.EVT_BUTTON, self.OnPause)
play_button.Bind(wx.EVT_BUTTON, self.OnPlay)
time_button.Bind(wx.EVT_BUTTON, self.OnTime)
self.Show()
def OnCloseWindow(self, event):
self.Destroy()
def OnPause(self, event):
print "Pause pressed"
def OnPlay(self, event):
print "Play pressed"
def OnTime(self, event):
print "Time pressed"
if __name__ == "__main__":
app = wx.App()
frame = TestFrame(None, -1, "wxBitmap Test")
app.MainLoop()