0

在此处输入图像描述

有没有办法在我的程序的顶部和底部为 3 和 4 实现填充?

或者有没有像添加 \n 等的解决方法......

我觉得行号和样式文本离顶部和底部太近了。

4

2 回答 2

1

使用嵌套在 sizer 内的相同颜色的面板作为一种肮脏的解决方法怎么样?

import wx
import wx.stc as stc

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel = wx.Panel(self)

        self.text = stc.StyledTextCtrl(self.panel)
        self.text.SetWindowStyle(self.text.GetWindowStyle() | wx.NO_BORDER)
        self.text.StyleSetSpec(stc.STC_STYLE_DEFAULT, "size:15,face:Courier New")
        self.text.SetWrapMode(stc.STC_WRAP_WORD)
        self.text.SetMarginLeft(50)
        self.text.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#FFFFFF")

        self.menu = wx.Menu()
        self.menu.Append(wx.ID_ABOUT, "&About", "Information about this program")
        self.menu_bar = wx.MenuBar()
        self.menu_bar.Append(self.menu, "&File")
        self.SetMenuBar(self.menu_bar)

        self.panel_top = wx.Panel(self.panel, size = (20, -1))
        self.panel_top.SetBackgroundColour(wx.WHITE)
        self.panel_bottom = wx.Panel(self.panel, size = (20, -1))
        self.panel_bottom.SetBackgroundColour(wx.WHITE)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panel_top, 0, wx.ALL | wx.EXPAND)
        self.sizer.Add(self.text, 1, wx.ALL | wx.EXPAND)
        self.sizer.Add(self.panel_bottom, 0, wx.ALL | wx.EXPAND)

        self.border = wx.BoxSizer()
        self.border.Add(self.sizer, 1, wx.ALL | wx.EXPAND, border=20)

        self.panel.SetSizerAndFit(self.border)

        self.text.Bind(stc.EVT_STC_CHANGE, self.OnChange)
        self.Show()

        self.text.SetText("Line!\n"*3)

    def OnChange(self, e):
        lines = self.text.GetLineCount()
        width = self.text.TextWidth(stc.STC_STYLE_LINENUMBER, str(lines)+" ")
        self.text.SetMarginWidth(0, width)


if __name__ == "__main__":
    app = wx.App(False)
    win = MainWindow(None)
    app.MainLoop()

对于您的代码,将其修改如下:

  self.panel_top = wx.Panel(self.panel, size = (20, -1))
  self.panel_top.SetBackgroundColour(wx.BLACK)
  self.panel_bottom = wx.Panel(self.panel, size = (20, -1))
  self.panel_bottom.SetBackgroundColour(wx.BLACK)

  #### Add the STC to a Sizer. ####
  sizer = wx.BoxSizer(wx.VERTICAL)
  sizer.Add(self.panel_top, 0, wx.EXPAND,border=20)
  sizer.Add(self.text, 1, wx.EXPAND,border=20)
  sizer.Add(self.panel_bottom, 0, wx.EXPAND,border=20)
  self.panel.SetSizer(sizer)
于 2013-01-16T18:48:22.377 回答
0

不,我不认为 Scintilla 具有控制顶部和底部边距大小的属性。

于 2013-01-16T18:35:39.427 回答