IDLE使用

版权声明:转载请标明出处 https://blog.csdn.net/qq_41556318/article/details/86016607

IDLE有一些使用技巧,有时候要用的时候却记不起来了,为了方便以后使用,我统计了一下:

如何debug

1.设置断点:在Python编辑器中要调试的代码行右击->Set Breakpoint,之后该行底色就变黄了
2.打开debugger:Python Shell->Debug->Debugger
3.编辑窗口按F5
4.debug过程略
•        Go表示运行完相当于eclipse的F8,不过按F5后先要Go一下才能往下走,默认是不运行的
•        Step表示一步一步相当于eclipse的F5
•        Over表示跳过函数方法相当于eclipse的F6
•        Out表示跳出本函数相当于eclipse的F7

IDLE编辑器快捷键

自动补全代码        Alt+/(查找编辑器内已经写过的代码来补全)
补全提示              Ctrl+Shift+space(默认与输入法冲突,修改之)
(方法:Options->configure IDLE…->Keys-> force-open-completions
提示的时候只要按空格就出来对于的,否则翻上下键不需要按其他键自动就补全了)
后退                    Ctrl+Z
重做                    Ctrl+Shift+Z
加缩进                 Ctrl+]
减缩进                 Ctrl+[
加注释                 Alt+3
去注释                 Alt+4

ALT + Q :在IDLE 编辑器中,将Python代码进行格式化布局

Python Shell快捷键

自动补全同上
上一条命令           Alt+P
下一条命令           Alt+N

在Python IDLE中实现清屏

首先创建一个名为 ClearWindow.py 的文件,写入下面的代码:

"""

Clear Window Extension
Version: 0.2

Author: Roger D. Serwy
        [email protected]

Date: 2009-06-14

It provides "Clear Shell Window" under "Options"
with ability to undo.

Add these lines to config-extensions.def

[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>


"""

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

        self.text.bind("<<undo>>", self.undo_event)  # add="+" doesn't work

    def undo_event(self, event):
        text = self.text
        
        text.mark_set("iomark2", "iomark")
        text.mark_set("insert2", "insert")
        self.editwin.undo.undo_event(event)

        # fix iomark and insert
        text.mark_set("iomark", "iomark2")
        text.mark_set("insert", "insert2")
        text.mark_unset("iomark2")
        text.mark_unset("insert2")
        

    def clear_window2(self, event): # Alternative method
        # work around the ModifiedUndoDelegator
        text = self.text
        text.undo_block_start()
        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")
        text.undo_block_stop()
        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)
 

将这个文件放在Python X\Lib\idlelib目录下(X为你的python版本),然后在这个目录下找到config-extensions.def这个文件(idle扩展的配置文件),以记事本的方式打开它

打开config-extensions.def  后在句末加上这样几句:

[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l> or <Control-Key-L>

然后保存退出就可以了。

打开python的idle,看看options是不是多了一个选项clear shell window  ctrl+L

快捷键 :Ctrl + L 或者 Ctrl + l(小写 l 和大写 L 都可以了)

猜你喜欢

转载自blog.csdn.net/qq_41556318/article/details/86016607
今日推荐