如何用 wxPython 隐藏垂直和水平滚动条?

how to hide the Vertical and horizontal Scrollbars with wxPython ?

我正在使用此代码创建文本 window 但我不知道如何隐藏滚动条 我看到一些 wxpython 不支持的答案,所以有什么想法吗?? 谢谢!

注意:隐藏滚动条不是禁用滚动
谢谢 :)

import wx
import wx.lib.dialogs
import wx.stc as stc



faces = {'times':'Times New Roman','helv':"Arial","size":18}

class MainWindow(wx.Frame):
    def __init__(self,parent,title):
        self.filepath =''
        self.leftMarginWidth = 25
        wx.Frame.__init__(self,parent,title=title,size=(1350,720))

        self.control=stc.StyledTextCtrl(self,style=wx.TE_MULTILINE | wx.TE_WORDWRAP|wx.TE_NO_VSCROLL)
        self.control.CmdKeyAssign(ord("+"),stc.STC_SCMOD_CTRL,stc.STC_CMD_ZOOMIN) #Ctrl + + to zoom in
        self.control.CmdKeyAssign(ord("-"),stc.STC_SCMOD_CTRL,stc.STC_CMD_ZOOMOUT) #Ctrl + - to zoom out
        self.control.SetViewWhiteSpace(False)
        self.control.SetMargins(5,0)
        self.control.SetMarginType(1,stc.STC_MARGIN_NUMBER)
        self.control.SetMarginWidth(1,self.leftMarginWidth)
        self.control.Bind(wx.EVT_CHAR,self.OnCharEvent)

        #don't forget the statusBar
        #file men if you want it 
        self.Show()

    def OnSave(self,e):
        try:
            f= open(self.filepath,"w")
            f.write(self.control.GetText())
            f.close()
        except:
            self.OnSaveAs(self) 
    def OnSaveAs(self,e):
        try:
            dlg=wx.FileDialog(self,'save file as',self.filepath,"untitled","*.*",wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
            print dlg
            if (dlg.ShowModal()== wx.ID_OK):
                self.filepath = dlg.GetPath()
                f=open(self.filepath,"w")
                f.write(self.control.GetText())
                f.close()
            dlg.Destroy()
        except:
            pass
    def OnOpen(self,e):
        dlg=wx.FileDialog(self,"Choose a file",self.filepath,'',"*.*",wx.FD_OPEN)
        if(dlg.ShowModal() == wx.ID_OK):
            self.filepath = dlg.GetPath()
            f=open(self.filepath,"r")
            self.control.SetText(f.read()) 
            f.close()
        dlg.Destroy()

    def OnCharEvent(self,e):
        keycode=e.GetKeyCode()
        print keycode
        if (keycode == 15):
            self.OnOpen(self)
        elif keycode == 19:
            self.OnSave(self)
        else:
            e.Skip()

app=wx.App()
frame = MainWindow(None,"my text Editor")

app.MainLoop()

image

StyledTextCtrl class 有 SetUseHorizontalScrollBarSetUseVerticalScrollBar 方法。

https://wxpython.org/Phoenix/docs/html/wx.stc.StyledTextCtrl.html#wx.stc.StyledTextCtrl.SetUseHorizontalScrollBar