文本小部件中的TAB键空间计数

时间:2019-11-22 19:36:34

标签: python tkinter

set string1 [regsub -all {\W} $string {\\&}] 库中, Tab tkinter小部件中添加了8个空格。

如何更改空格数?

我的Text()代码:

tkinter

1 个答案:

答案 0 :(得分:1)

我从更改了您的代码 Python/Tkinter: How to set text widget contents to the value of a variable?

from tkinter import *

win = Tk()

txt = Text()
txt.pack()

def tab(arg):
    print("tab pressed")
    txt.insert(INSERT, " " * 4) #this number is where you set the amount of spaces to add per tab
    return 'break'

txt.bind("<Tab>", tab)

win.mainloop()