wxPython.TextCtrl选项卡宽度



如何在wx中将Tab宽度设置为4而不是8。文本Ctrl
如果不可能,使用什么替代wx。文本Ctrl?

注意:
myxtCtrl.setDefaultStyle(wx.TextAttr().setTabs([…])不工作!

SetTabs的设置单位为十分之一毫米。不知道为什么,这太残忍了!

import wx
TAB = 4
TEST = "".join([" "*i*TAB + "|n" + "t"*i + "|n" for i in range(1, 30, 2)])
class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)
        self.text = wx.TextCtrl(self.panel, style=wx.TE_PROCESS_TAB | wx.TE_RICH | wx.TE_MULTILINE)
        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.text, 1, wx.ALL | wx.EXPAND)
        self.text.Bind(wx.EVT_SIZE, self.SetTabs)
        self.panel.SetSizerAndFit(self.sizer)
        self.Show()
        self.text.SetValue(TEST)
    def SetTabs(self, e):  
        pixel_width_in_mm = 25.4 / wx.ScreenDC().GetPPI()[0]
        space_width_in_pixels = self.text.GetTextExtent(" ")[0]
        tab_width_in_tenth_of_mm = (10 * TAB * space_width_in_pixels * pixel_width_in_mm)
        textctrl_width_in_mm = (10 * self.text.GetSize()[0] * (1 / pixel_width_in_mm))
        nr_of_tabs = int(textctrl_width_in_mm / tab_width_in_tenth_of_mm)
        tabs = [int((i+1)*tab_width_in_tenth_of_mm) for i in range(nr_of_tabs)]
        attr = wx.TextAttr()
        attr.SetTabs(tabs)
        self.text.SetDefaultStyle(attr)
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

像这样:

    wx.TextCtrl(panel, pos = (10, 10), size = (40, 20))

相关内容

  • 没有找到相关文章

最新更新