如何使用 wxPython 隐藏垂直和水平滚动条? [英] how to hide the Vertical and horizontal Scrollbars with wxPython ?

查看:47
本文介绍了如何使用 wxPython 隐藏垂直和水平滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Am using this code to create a text window but i didn't figure out how to hide the Scrollbars I saw some answers that wxpython doesn't support that , so any ideas ?? thanks!

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

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()

图片

推荐答案

StyledTextCtrl 类具有 SetUseHorizo​​ntalScrollBarSetUseVerticalScrollBar 方法.

The StyledTextCtrl class has SetUseHorizontalScrollBar and SetUseVerticalScrollBar methods.

https://wxpython.org/Phoenix/docs/html/wx.stc.StyledTextCtrl.html#wx.stc.StyledTextCtrl.SetUseHorizo​​ntalScrollBar

这篇关于如何使用 wxPython 隐藏垂直和水平滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆