首页 > 解决方案 > 文本小部件中的 TAB 键空间计数

问题描述

tkinterTab中将 +8 空间放入Text()小部件。

如何更改空格数?

我的tkinter代码:

from tkinter import *

win = Tk()

txt = Text()
txt.pack()

win.mainloop()

.

标签: pythontkinter

解决方案


我从 Python/Tkinter 对您的代码进行了此更改 :如何将文本小部件内容设置为变量的值?

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

推荐阅读