如何旋转wxButton标签?

时间:2019-04-04 09:09:49

标签: user-interface button wxpython

我正在用wxpython创建一个图形用户界面,我想插入一个垂直旋转标签的按钮(请参见下面的示例)。 我已经研究了文档并做了一些互联网搜索,但是找不到有关如何执行操作的信息。 有可能做到吗?如果是的话,将不胜感激。

enter image description here

谢谢。 伊沃

1 个答案:

答案 0 :(得分:1)

我能想到的唯一方法是使用您准备的BitmapButton
您可以通过编程方式来做到,例如

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):

        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400, 300))
        panel = wx.Panel(self)
        #Create an image
        simg = wx.Image(150,25,True)
        #Change from black to grey
        simg.Replace(0,0,0,200,200,200)
        bitmap = simg.ConvertToBitmap()
        #Write required text
        dc = wx.MemoryDC(bitmap)
        dc.SetTextForeground(wx.BLACK)
        dc.DrawText("Vertical Button", 10, 0)
        del dc
        img = bitmap.ConvertToImage()
        img1 = img.Rotate90(False)
        img2 = img.Rotate90()
        bmp = img1.ConvertToBitmap()
        bmp2 = img2.ConvertToBitmap()

        btn1 = wx.BitmapButton(panel, -1, bmp, pos=(10,10))
        btn2 = wx.BitmapButton(panel, -1, bmp2, pos=(350,10))
        btn1.Bind(wx.EVT_BUTTON, self.BTN1)
        btn2.Bind(wx.EVT_BUTTON, self.BTN2)

        #Just for fun create a button with vertical text

        simg = wx.Image(25,110,True)
        #Change from black to grey
        simg.Replace(0,0,0,200,200,200)
        bitmap = simg.ConvertToBitmap()
        #Write required text
        dc = wx.MemoryDC(bitmap)
        dc.SetTextForeground(wx.BLACK)
        dc.DrawText("V", 7, 0)
        dc.DrawText("e", 8, 15)
        dc.DrawText("r", 8, 30)
        dc.DrawText("t", 8, 45)
        dc.DrawText("i", 8, 60)
        dc.DrawText("c", 8, 75)
        dc.DrawText("l", 8, 90)
        del dc
        img3 = bitmap.ConvertToImage()
        bmp3 = img3.ConvertToBitmap()
        btn3 = wx.BitmapButton(panel, -1, bmp3, pos=(175,10))
        btn3.Bind(wx.EVT_BUTTON, self.BTN3)


    def BTN1(self,event):
        print("Left Button")

    def BTN2(self,event):
        print("Right Button")

    def BTN3(self,event):
        print("Middle Button")

app = wx.App()
frame = MyFrame(None, 'Vertical Buttons')
frame.Show()
app.MainLoop()

enter image description here