• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    手把手教你怎么讓Python IDLE清屏 idle清屏設置

    相信有良多在Windows上利用Python的小伙伴城市想過如許一個問題——Python怎么樣才能在IDLE清屏?IDLE是沒有如許的功能的。

    其實,我們可以擴展IDLE,使得我們在開辟和測試的時辰加倍便當。

    今天小編就教大師怎么擴展IDLE,使其撐持清屏功能。

    東西/原料

    • Python for Windows

    方式/步調

    1. 1

      起頭之前,我們必需要知道:

      IDLE默認沒有清屏功能,所以我們想要使其可以實現清屏,我們就必需要擴展IDLE。

      我們需要下載一個叫ClearWindow.py的擴展文件

      如圖

    2. 2

      其代碼如下:

      class ClearWindow:

          menudefs = [

              ('options', [None,

                     ('Clear Shell Window', '<<clear-window>>'),

             ]),]

       

          def __init__(self, editwin):

              self.editwin = editwin

              self.text = self.editwin.text

              self.text.bind("<<clear-window>>", self.clear_window)

          def clear_window2(self, event): # Alternative method

              # work around the ModifiedUndoDelegator

              text = self.text

              text.mark_set("iomark2", "iomark")

              text.mark_set("iomark", 1.0)

              text.delete(1.0, "iomark2 linestart")

              text.mark_set("iomark", "iomark2")

              text.mark_unset("iomark2")

              if self.text.compare('insert', '<', 'iomark'):

                  self.text.mark_set('insert', 'end-1c')

              self.editwin.set_line_and_column()

          def clear_window(self, event):

              # remove undo delegator

              undo = self.editwin.undo

              self.editwin.per.removefilter(undo)

              # clear the window, but preserve current command

              self.text.delete(1.0, "iomark linestart")

              if self.text.compare('insert', '<', 'iomark'):

                  self.text.mark_set('insert', 'end-1c')

              self.editwin.set_line_and_column()

       

              # restore undo delegator

              self.editwin.per.insertfilter(undo)

      小伙伴可以復制以上代碼保留當作一個ClearWindow.py文件

      同樣,我們也可以到bugs.python.org/file14116/ClearWindow.py去復制保留。

    3. 3

      我們打開Python的安裝目次,找到Lib目次下的idlelib目次

      然后把上面保留的ClearWindow.py拷貝到idlelib目次下。

      找到config-extensions.def設置裝備擺設文件并打開它。

      如圖

    4. 4

      在文件末從頭至尾插手以下設置裝備擺設:

      [ClearWindow]

      enable=1

      enable_editor=0

      enable_shell=1

      [ClearWindow_cfgBindings]

      clear-window=<Control-Key-l>

      來詮釋下什么意思

      enable=1

      #1為真 意思就是啟用這個擴展

      enable_editor=0

      #編纂器禁用這個擴展

      enable_shell=1

      #IDLE Shell啟動擴展

      clear-window=<Control-Key-l>

      #設置快捷鍵為Ctrl + L

    5. 5

      此時我們打開Python IDLE Shell

      點擊Options,可以看到我們的擴展被當作功加載。

      同樣,我們可以按下Ctrl + L進行清屏操作。我們還可以經由過程clear-window=<Control-Key-l>點竄快捷鍵,例如點竄為ctrl + 3,則是clear-window=<Control-Key-3>

      怎么樣,學會沒?點一波存眷吧(*^__^*) 

    是否幫到了您?若是有幫到您,請點個存眷、點個投票、點個分享、點個贊

    1. 1

      怎么存眷?

      在經驗的右上角小編頭像旁邊點擊存眷,如圖。

    2. 2

      怎么點贊?

      請在經驗左側點贊,如圖。

    3. 3

      怎么投票?

      在經驗的下方點擊投票,如圖。

    4. 4

      若是感覺小編寫的還不錯,可以動動鼠標把它分享給您的伴侶。

      若何分享,鼠標移動到右下角第一個按鈕上,在彈出的選項中進行分享,如圖。

      不盡感謝感動。

    注重事項

    • 人生苦短,我用Python
    • 若有疑問,點擊左下角的投票或者有得給小編留言,小編看到會第一時候答復您,感謝
    • 若是喜好本經驗,請存眷我。可以把它分享給您的伴侶,請點個投票點個保藏。感謝,您的撐持是我最年夜的動力。
    • 發表于 2018-07-07 00:00
    • 閱讀 ( 977 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    admin
    admin

    0 篇文章

    作家榜 ?

    1. xiaonan123 189 文章
    2. 湯依妹兒 97 文章
    3. luogf229 46 文章
    4. jy02406749 45 文章
    5. 小凡 34 文章
    6. Daisy萌 32 文章
    7. 我的QQ3117863681 24 文章
    8. 華志健 23 文章

    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆