Wrapping issues with wxPython

I am building an app using wxPython but I am having trouble with the text wrapping on the StaticText elements. The wrapping is working for other elements without using Wrap().

With this test, you should be able to see that any of the extended values in the list are not being wrapped properly, and instead cut off.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import wx
import wx.lib.agw.aui as aui
import wx.html
def test():
pass
def text(parent, txt):
text_element = wx.StaticText(parent, label=txt)
return text_element
def box(parent='', static=False, label='', direction=wx.HORIZONTAL):
orient = direction
text = label if label else ''
if static:
# Create a static box and static box sizer if the static parameter is True
static_box = wx.StaticBox(parent,size=-1, label=text)
box_sizer = wx.StaticBoxSizer(static_box, orient)
else:
# Create a regular box sizer if the static parameter is False
box_sizer = wx.BoxSizer(orient)
return box_sizer
def list(parent, linked_items=None, regular_items=None):
if not linked_items and not regular_items:
raise ValueError("Linked list items AND regular list items cannot be None")
vbox = box(direction=wx.VERTICAL)
item_list = []
number = 1
for item_l in linked_items:
hbox = box()
left_label = text(parent, f"{number}.")
item_list.append(left_label)
hbox.Add(left_label, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, border=5)
print(len(item_l[0])*14)
html = wx.html.HtmlWindow(parent, size=(len(item_l[0])*8, 40),style=wx.html.HW_SCROLLBAR_NEVER)
html.SetPage(f'<span style="color: #FF0000" ><a href="{item_l[0]}">{item_l[0]}</a></span>')
html.Bind(wx.html.EVT_HTML_LINK_CLICKED, item_l[1])
item_list.append(html)
hbox.Add(html, proportion=1, flag=wx.EXPAND | wx.ALL)
right_label = text(parent, f"{item_l[2]}")
item_list.append(right_label)
hbox.Add(right_label, proportion= 1, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5)
vbox.Add(hbox,proportion=0,flag=wx.EXPAND | wx.ALL)
number += 1
for item_r in regular_items:
label = text(parent, f"{number}. {item_r}")
item_list.append(label)
vbox.Add(label, proportion= 0, flag= wx.EXPAND | wx.ALL, border=5)
number += 1
vbox.Layout()
return vbox, item_list
if __name__ == '__main__':
app = wx.App
frame = wx.Frame(None, title='title', size = (1024,768))
_mgr = aui.AuiManager(frame)
panel = wx.Panel(frame)
main_sizer = box()
side_center = box()
center_sizer = box(direction=wx.VERTICAL)
linked_list = [
['Create a New Project',test, ': rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'],
['Open an Existing Project',test, ': Pick up the call where you left off.'],
['Explore TestValue Cases',test, ': rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'],
]
regular_list = [
'rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.',
'rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'
]
list_size, list_items = list(panel, linked_list, regular_list)
center_sizer.Add(list, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
side_center.Add(center_sizer, flag= wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border=100)
main_sizer.Add(side_center,flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.LEFT, border=200)
panel.SetSizer(main_sizer)
panel.Layout()
panel.Refresh()
_mgr.AddPane(panel, aui.AuiPaneInfo().Name('panel').CenterPane())
_mgr.Update()
</code>
<code>import wx import wx.lib.agw.aui as aui import wx.html def test(): pass def text(parent, txt): text_element = wx.StaticText(parent, label=txt) return text_element def box(parent='', static=False, label='', direction=wx.HORIZONTAL): orient = direction text = label if label else '' if static: # Create a static box and static box sizer if the static parameter is True static_box = wx.StaticBox(parent,size=-1, label=text) box_sizer = wx.StaticBoxSizer(static_box, orient) else: # Create a regular box sizer if the static parameter is False box_sizer = wx.BoxSizer(orient) return box_sizer def list(parent, linked_items=None, regular_items=None): if not linked_items and not regular_items: raise ValueError("Linked list items AND regular list items cannot be None") vbox = box(direction=wx.VERTICAL) item_list = [] number = 1 for item_l in linked_items: hbox = box() left_label = text(parent, f"{number}.") item_list.append(left_label) hbox.Add(left_label, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, border=5) print(len(item_l[0])*14) html = wx.html.HtmlWindow(parent, size=(len(item_l[0])*8, 40),style=wx.html.HW_SCROLLBAR_NEVER) html.SetPage(f'<span style="color: #FF0000" ><a href="{item_l[0]}">{item_l[0]}</a></span>') html.Bind(wx.html.EVT_HTML_LINK_CLICKED, item_l[1]) item_list.append(html) hbox.Add(html, proportion=1, flag=wx.EXPAND | wx.ALL) right_label = text(parent, f"{item_l[2]}") item_list.append(right_label) hbox.Add(right_label, proportion= 1, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5) vbox.Add(hbox,proportion=0,flag=wx.EXPAND | wx.ALL) number += 1 for item_r in regular_items: label = text(parent, f"{number}. {item_r}") item_list.append(label) vbox.Add(label, proportion= 0, flag= wx.EXPAND | wx.ALL, border=5) number += 1 vbox.Layout() return vbox, item_list if __name__ == '__main__': app = wx.App frame = wx.Frame(None, title='title', size = (1024,768)) _mgr = aui.AuiManager(frame) panel = wx.Panel(frame) main_sizer = box() side_center = box() center_sizer = box(direction=wx.VERTICAL) linked_list = [ ['Create a New Project',test, ': rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'], ['Open an Existing Project',test, ': Pick up the call where you left off.'], ['Explore TestValue Cases',test, ': rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'], ] regular_list = [ 'rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.', 'rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.' ] list_size, list_items = list(panel, linked_list, regular_list) center_sizer.Add(list, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) side_center.Add(center_sizer, flag= wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border=100) main_sizer.Add(side_center,flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.LEFT, border=200) panel.SetSizer(main_sizer) panel.Layout() panel.Refresh() _mgr.AddPane(panel, aui.AuiPaneInfo().Name('panel').CenterPane()) _mgr.Update() </code>
import wx
import wx.lib.agw.aui as aui
import wx.html

def test():
    pass
    
def text(parent, txt):
    text_element = wx.StaticText(parent, label=txt)
    return text_element

def box(parent='', static=False, label='', direction=wx.HORIZONTAL):
    orient = direction
    text = label if label else ''

    if static:
        # Create a static box and static box sizer if the static parameter is True
        static_box = wx.StaticBox(parent,size=-1, label=text)
        box_sizer = wx.StaticBoxSizer(static_box, orient)
    else:
        # Create a regular box sizer if the static parameter is False
        box_sizer = wx.BoxSizer(orient)

    return box_sizer

def list(parent, linked_items=None, regular_items=None):
    if not linked_items and not regular_items:
        raise ValueError("Linked list items AND regular list items cannot be None")
    
    vbox = box(direction=wx.VERTICAL)
    
    item_list = []
    number = 1
    for item_l in linked_items:
        hbox = box()
        left_label = text(parent, f"{number}.")
        item_list.append(left_label)
        hbox.Add(left_label, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, border=5)
        
        print(len(item_l[0])*14)
        html = wx.html.HtmlWindow(parent, size=(len(item_l[0])*8, 40),style=wx.html.HW_SCROLLBAR_NEVER)
        html.SetPage(f'<span style="color: #FF0000" ><a href="{item_l[0]}">{item_l[0]}</a></span>')
        html.Bind(wx.html.EVT_HTML_LINK_CLICKED, item_l[1])
        item_list.append(html)
        hbox.Add(html, proportion=1, flag=wx.EXPAND | wx.ALL)
        
        
        right_label = text(parent, f"{item_l[2]}")
        item_list.append(right_label)
        hbox.Add(right_label, proportion= 1, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5)
        vbox.Add(hbox,proportion=0,flag=wx.EXPAND | wx.ALL)
        
        number += 1
    for item_r in regular_items:
        label = text(parent, f"{number}. {item_r}")
        item_list.append(label)
        vbox.Add(label, proportion= 0, flag= wx.EXPAND | wx.ALL, border=5)
        number += 1
    
    vbox.Layout()
    
    return vbox, item_list

if __name__ == '__main__':
    app = wx.App
    frame = wx.Frame(None, title='title', size = (1024,768))
    _mgr = aui.AuiManager(frame)
    panel = wx.Panel(frame)
    
    main_sizer = box()
    side_center = box()
    center_sizer = box(direction=wx.VERTICAL)
    
    linked_list = [
        ['Create a New Project',test, ': rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'],
        ['Open an Existing Project',test, ': Pick up the call where you left off.'],
        ['Explore TestValue Cases',test, ': rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'],
    ]
    regular_list = [
        'rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.',
        'rquoipktdvohixqzvogkplqheturogclr gpzpvqujlyxrrcbolmyjfjruojkudsodfevgbxypnnoalvhyxsdirmbrnss.'
    ]

    list_size, list_items = list(panel, linked_list, regular_list)

    center_sizer.Add(list, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
        
    side_center.Add(center_sizer, flag= wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border=100)
        
    main_sizer.Add(side_center,flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.LEFT, border=200)

    panel.SetSizer(main_sizer)
    panel.Layout()
    panel.Refresh()

    _mgr.AddPane(panel, aui.AuiPaneInfo().Name('panel').CenterPane())
    _mgr.Update()

Is there any way to avoid this? Or should I give up on the Python-based UI? I’m only using wxPython since it was easy to implement a large application before a deadline. I can switch it to something else (If that is the case, leave a suggestion in the comment/answer).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật