1

In tkinter library Tab puts +8 space into Text() widget.

How do I change number of spaces?

My tkinter code:

from tkinter import *

win = Tk()

txt = Text()
txt.pack()

win.mainloop()

.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
ForceVII
  • 355
  • 2
  • 16
  • You have to create a post for each library, the questions that ask the same for several libraries is off-topic and it will be more difficult to help you – eyllanesc Nov 22 '19 at 19:39
  • when I run the code on my computer there is only a blank text box. are you saying that in the text box there are 8 tabs for you? – Josh Harold Nov 22 '19 at 19:39
  • 1
    Have you read the documentation on the Text widget? There are options specifically to deal with tabs and stabstops. – Bryan Oakley Nov 22 '19 at 19:40
  • When we click [TAB] key in keybord it puts 8 or more spaces. I want to change it. Can I do it? – ForceVII Nov 22 '19 at 19:41
  • 1
    Bryan Oakley Thanks. I fund there. Text(tabs=`variable`) is works. – ForceVII Nov 22 '19 at 19:46
  • Are you asking how to literally insert four spaces, or are you asking how to set a tabstop that is 4 spaces wide? The tab key normally does _not_ insert 8 spaces. It inserts a single tab, and tab stops default to being 8 characters. Literally inserting 4 spaces is different than inserting a tab with a tabstop at 4 characters are completely different things. – Bryan Oakley Nov 22 '19 at 20:24

1 Answers1

1

I made this change to your code from 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()
Josh Harold
  • 103
  • 7