如何在sizer中的wxpython中右对齐图像

问题描述 投票:0回答:1

我有两张图像,我想将一个图像居中对齐,而另一个图像向右对齐。

以某种方式将两个图像都对准中心。如何强制它们以不同的方式对齐?

先谢谢您!

def __init__(self, parent):
    wx.Frame.__init__(self, parent, -1, "Index Calculator", size=(1200, 1000))
    self.panel = wx.Panel(self)
    sizer = wx.BoxSizer(wx.VERTICAL)
    self.SetBackgroundColour("white")
    self.SetIcon(wx.Icon("images/logo.bmp"))

    png = wx.Image("images/logo.bmp", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.img = wx.StaticBitmap(self.panel, -1, png, (10, 5), (png.GetWidth(), png.GetHeight()))

    png_1 = wx.Image("images/logo1.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.img1 = wx.StaticBitmap(self.panel, -1, png_1, (10, 5), (png.GetWidth(), png.GetHeight()))

    self.log_text = wx.StaticText(self.panel, label="Results", pos=(6, 1))
    self.log = wx.TextCtrl(self.panel, wx.ID_ANY, size=(250, 100),
                           style=wx.TE_MULTILINE | wx.TE_READONLY | wx.VSCROLL)
    self.button = wx.Button(self.panel, label="Generate Index Score")

    # self.end_text = wx.StaticText(self.panel, label="Powered by", pos=(400, 300))

    sizer.Add(self.img, 0, wx.EXPAND | wx.ALL, 5)
    sizer.Add(self.log_text, 0, wx.EXPAND | wx.ALL, 5)
    sizer.Add(self.log, 0, wx.EXPAND | wx.ALL, 5)
    sizer.Add(self.button, 0, wx.EXPAND | wx.ALL, 5)
    sizer.Add(self.img_1, 0, wx.EXPAND | wx.ALL, 5)

    self.panel.SetSizerAndFit(sizer)
    self.Bind(wx.EVT_BUTTON, self.OnButton)
python wxpython
1个回答
0
投票

如果展开,则sizer不能进行任何对齐,因为该小部件已展开到所有可用空间。首先,尝试更改

 sizer.Add(self.log_text, 0, wx.ALL | wx.ALIGN_RIGHT, 5)

看看是否有效。我们从静态文本开始,因为图像总是比较困难。当您看到它有效时,可以尝试与图片相同,使用wx.ALIGN_RIGHT,wx.ALIGN_CENTER。

© www.soinside.com 2019 - 2024. All rights reserved.