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

时间:2016-07-19 12:46:06

标签: wxpython

使用此代码创建文本窗口但我没有弄清楚如何隐藏滚动条 我看到了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

1 个答案:

答案 0 :(得分:1)

StyledTextCtrl班级有SetUseHorizontalScrollBarSetUseVerticalScrollBar方法。

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