【问题标题】:How to rotate wxButton label?如何旋转 wxButton 标签?
【发布时间】:2019-08-25 23:27:03
【问题描述】:

我正在使用 wxpython 创建一个图形用户界面,我想插入一个带有垂直旋转标签的按钮(参见下面的示例)。 我查看了文档并进行了一些互联网搜索,但我找不到如何做到这一点的信息。 有可能做到吗?如果是的话,任何帮助将不胜感激。

谢谢。 伊沃

【问题讨论】:

    标签: user-interface button wxpython


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-29
      • 2016-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 2021-04-09
      相关资源
      最近更新 更多