0

I want to create a text widget, in order to write some credentials. How can I insert a text that I can't modify, but still be able to write in the Text widget?

text = Text(root, wrap=NONE,
            xscrollcommand=xscrollbar.set,
            yscrollcommand=yscrollbar.set)

text.insert(INSERT, "Name: ")
text.configure(state='disabled')

I tried like this and it is ok, because I can't modify the text "Name: ", but the problem is that I can't write anymore in the Text widget.

martineau
  • 119,623
  • 25
  • 170
  • 301
Gheorghe Gh
  • 41
  • 1
  • 10

1 Answers1

1

If you want to add some text and then disable the text box to not be modified then you should set the state first to normal, insert the text then set it back to disabled. Like this:

    text.configure(state='normal')
    text.delete('1.0', 'end')
    text.insert('1.0', "Name: ")
    text.configure(state='disabled')

This will clear the text box first, if you don't want that, just remove the second line. You can check here for how to disable just the first part of the text widget.

faressalem
  • 574
  • 6
  • 20
  • 1
    The user can't write in Text widget after i run the code. The whole widget gets disabled, not only the text ‘Name:’. I want so that the user can't delete/modify the text 'Name:', that i insert for him, but i want him to be able to write in the widget. – Gheorghe Gh Apr 29 '20 at 21:49
  • @GheorgheGh Yes, check the link it solves the same problem. – faressalem Apr 29 '20 at 21:54