WxPython使用GridBagSizer调整图像大小

时间:2015-02-23 03:23:35

标签: user-interface wxpython

如果这太简单了,我很抱歉...我试图在我的第一个GUI中添加一个徽标,但是,我不确定调整它的最佳方法是什么。目前,我正在使用image.Scale调整徽标大小并放置GridBagSizer

    self.image = wx.Image("logo11w.png", wx.BITMAP_TYPE_ANY)
    w = self.image.GetWidth()
    h = self.image.GetHeight()
    self.image = self.image.Scale(w/8, h/8)
    self.sb1 = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.image))
    self.sizer.Add(self.sb1, pos=(0, 0), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=15)

enter image description here

我想知道是否有自动方式来做到这一点?由于我使用GridBagSizer,是否可以为我的徽标留下一个“网格”(例如,1 x 1“框”)?提前谢谢!

代码:

import wx

class landing_frame(wx.Frame):
    def __init__(self, parent, title):    
        wx.Frame.__init__(self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size(800, 600), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        self.font1 = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.BOLD) 
        self.InitUI()
        self.Centre()
        self.Show()     

    def InitUI(self):
        self.panel = wx.Panel(self)
        self.sizer = wx.GridBagSizer(5, 15)

        self.image = wx.Image("logo11w.png", wx.BITMAP_TYPE_ANY)
        w = self.image.GetWidth()
        h = self.image.GetHeight()
        self.image = self.image.Scale(w/8, h/8)
        self.sb1 = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.image))
        self.sizer.Add(self.sb1, pos=(0, 0), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=15)


        self.text1 = wx.StaticText(self.panel, label="Welcome!")
        self.sizer.Add(self.text1, pos=(0, 2), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=15)

        line = wx.StaticLine(self.panel)
        self.sizer.Add(line, pos=(1, 0), span=(1, 5), flag=wx.EXPAND|wx.BOTTOM, border=10)

        self.text2 = wx.StaticText(self.panel, label="Question 1?")
        self.sizer.Add(self.text2, pos=(2, 0), flag=wx.ALL, border=10)

        self.sampleList = ['Op1', 'Op2', 'Op3']
        self.combo = wx.ComboBox(self.panel, 10, choices=self.sampleList)
        self.sizer.Add(self.combo, pos=(2, 1), span=(1, 5), flag=wx.EXPAND|wx.ALL, border=10)

        self.input1 = wx.StaticText(self.panel, 11, label="Please Enter Filepath")
        self.sizer.Add(self.input1, pos=(3, 0), span=(1, 1), flag=wx.ALL , border=10)

        self.input2 = wx.FilePickerCtrl(self.panel, 12, wx.EmptyString, u"Select a file", u"*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE )
        self.sizer.Add(self.input2, pos=(3, 1), span=(1, 20), flag=wx.EXPAND|wx.ALL, border=10)

        self.input3 = wx.StaticText(self.panel, 13, label="Additional inputs")
        self.sizer.Add(self.input3, pos=(4, 0), flag=wx.ALL , border=10)

        self.input4 = wx.TextCtrl(self.panel, 14, 'E.g. ...', wx.DefaultPosition, wx.DefaultSize, 0, wx.DefaultValidator )
        self.sizer.Add(self.input4, pos=(4, 1), span=(1, 10), flag=wx.EXPAND|wx.ALL, border=10)

        self.panel.SetSizer(self.sizer)

if __name__ == '__main__':
    app = wx.App(redirect=False, filename="mylogfile.txt")
    landing_frame(None, title="Test")
    app.MainLoop()

这是徽标 enter image description here

0 个答案:

没有答案