Search code examples
pythonwxpython

wxPyhton's StaticLine Constructor doesn't account for style parameter


I've recently started to learn wxPython, and I just need to display a vertical line to separate the buttons on my frame, however I tried to use the constructor StaticLine with the parameter "style = wx.LI_VERTICAL", like the documentation suggests, but when I run it displays a horizontal line. Even more strangely, when I check on the element with the method "IsVertical()" it returns True, as like nothing was wrong.

This is the code:

import wx
class Finestra(wx.Frame):

    def __init__ (self, genitore = None, titolo = "Netflix Preferences Carrier", dimensioni = (600, 450)):
        super(Finestra, self).__init__(parent = genitore, title = titolo, size = dimensioni, style = wx.MINIMIZE_BOX | wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER)
        self.Center()
        self.interfaccia()
        self.Show()

    def interfaccia(self):
        self.pannello =wx.Panel(self)
        self.pannello.SetBackgroundColour("white")
        self.sep = wx.StaticLine(self.pannello, pos = (50,50), size = (450, -1), style = wx.LI_VERTICAL)
        print(self.sep.IsVertical())

app = wx.App()
Finestra()
app.MainLoop()

What can I do to fix this?


Solution

  • The answer provided by @infinity77 is spot on.
    With a StaticLine where you declare a size

    either the height or the width (depending on whether the line if horizontal or vertical) is ignored.

    Try:

    import wx
    class Finestra(wx.Frame):
    
        def __init__ (self, genitore = None, titolo = "Netflix Preferences Carrier", dimensioni = (600, 450)):
            super(Finestra, self).__init__(parent = genitore, title = titolo, size = dimensioni, style = wx.MINIMIZE_BOX | wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER)
            self.Center()
            self.interfaccia()
            self.Show()
    
        def interfaccia(self):
            self.pannello =wx.Panel(self)
            self.pannello.SetBackgroundColour("blue")
            self.sep = wx.StaticLine(self.pannello, pos = (50,50), size = (-1, 350), style = wx.LI_VERTICAL)
    
    app = wx.App()
    Finestra()
    app.MainLoop()
    

    enter image description here