wxPython-4.0.3-防止扩展面板重叠

时间:2018-11-24 20:12:40

标签: python-3.x wxpython

我正在尝试构建一个wx.Panel对象,该对象具有多段单独包装的文本。当父面板太小时,段落会重叠并隐藏文本的某些部分。

如何在调整框架大小时创建带有流畅文本且不会被其他对象隐藏的面板?我希望在调整窗口大小时每个段落都能顺畅地流动;但是,当窗口变得太小时,我不希望段落彼此碰撞。

Panel.SetMinSize似乎不是候选对象,因为我永远都不知道基于窗口宽度的段落的最小高度。

#!/usr/bin/env python3
import wx

class MyFrame(wx.Frame):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        frame_sizer = wx.BoxSizer(wx.VERTICAL)

        text1 = wx.StaticText(self, label=self.big_string_one())
        text2 = wx.StaticText(self, label=self.big_string_two())
        color_panel = wx.Panel(self)
        color_panel.SetMinSize(size=wx.Size(-1, 10))
        color_panel.SetMaxSize(size=wx.Size(-1, 10))
        color_panel.BackgroundColour = "blue"
        frame_sizer.Add(text1, 1, flag=wx.ALL|wx.EXPAND, border=10)
        frame_sizer.Add(color_panel, 1, flag=wx.EXPAND)
        frame_sizer.Add(text2, 1, flag=wx.ALL|wx.EXPAND, border=10)
        self.SetSizer(frame_sizer)

    def big_string_one(self):
        retval =  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " \
                  "Ut ipsum lectus, mollis et pellentesque at, dapibus " \
                  "eu, laoreet dui. Class aptent taciti sociosqu ad litora " \
                  "torquent per conubia nostra, per inceptos himenaeos. " \
                  "Curabitur vestibulum, turpis fringilla convallis " \
                  "commodo, lectus lorem pharetra metus, non interdum magna " \
                  "convallis. Sed id metus in leo porttitor eleifend. " \
                  "Vivamus eget arcu at ligula ullamcorper consequat eget " \
                  "non turpis. Duis consequat ultrices dolor eu porta. Cras " \
                  "malesuada elementum urna, sed vulputate metus."
        return retval

    def big_string_two(self):
        retval =  "Morbi finibus hendrerit lacinia. Vestibulum eget metus " \
                  "vitae mi vehicula dignissim. Donec lobortis dignissim " \
                  "nisl, rutrum viverra nisl vulputate sed. Quisque quis " \
                  "placerat. Ut tincidunt dolor justo, fermentum lacinia " \
                  "metus bibendum a. Morbi ornare id ligula a eleifend. " \
                  "Phasellus at ultricies ante. Praesent malesuada nunc " \
                  "tortor, vel accumsan ex tempus at. Praesent eget ligula " \
                  "ac purus pharetra semper rutrum a nunc. Donec et " \
                  "lobortis mauris, non suscipit erat. Cras sagittis urna " \
                  "lobortis tortor vestibulum, vel pulvinar nisi finibus."
        return retval


if __name__ == "__main__":
    app = wx.App()
    my_frame = MyFrame(None).Show()
    app.MainLoop()

调整窗口大小,并且两个段落文本都能很好地流动 enter image description here

窗口现在变小了,第一段的文字被蓝色的分隔符裁剪了。 enter image description here

我的偏好是使所有段落的文本流畅,但当窗口变小时不要使它们彼此重叠。

0 个答案:

没有答案