我最近开始学习wxPython,我只需要显示一条垂直线来分隔框架上的按钮,但是我尝试使用带有参数“ style = wx.LI_VERTICAL”的构造函数StaticLine,例如文档建议,但运行时会显示一条水平线。更奇怪的是,当我使用“ IsVertical()”方法检查元素时,它返回True,就像没有错一样。
这是代码:
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()
该如何解决?
答案 0 :(得分:1)
不要显式传递“ size”参数,您是在告诉该行水平水平固定为450像素……如何将其显示为垂直线?>
答案 1 :(得分:1)
@ infinity77提供的答案很明显。
用StaticLine
声明size
高度或宽度(取决于该行是否 水平或垂直)。
尝试:
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()