[Tutor] Read - Only Text?

Tim Johnson tim@johnsons-web.com
Wed, 7 Mar 2001 08:29:12 -0900


Hi Michael:
	Thanks for the response and the mini tutorial.
It's been a great help! 
I am now able automatically insert text and disable the entry
of printable keystrokes. 
======================================================
As it is now, non-printing keystrokes like backspace, delete and
tab are still allowed, and I need to "stomp them out" also.
======================================================
I've included the code that I've written following my signature.
I'm looking for documentation and code on this subject as well.
Some questions are in the comments
-
Tim Johnson
-----------
"My shroe, my shroe, my dingkom for
  a shroe" - Anonymous
#######################################################
#!/usr/local/bin/python
from Tkinter import *
from ScrolledText import *
import sys
def quit(event):
	print "exit by button"
	sys.exit(0)
def test(event):
	add_text("hello")
def add_text(text):
	st.insert(END,text)
# this _should_ bypass the event system and not add "a" to the text widget
  # added by Michael 
def add_a(event):
	# where is docs on this event object? There is much for me to 
	# learn about the attributes, I think....
	if event.keysym == 'a':
		#pass
		print "You typed 'a' but I won't add it."
	else:
		pass
		#event.widget.insert(END, event.keysym)
main_window = Tk()
text_frame = Canvas(main_window)
text_frame.pack(expand=1,fill=BOTH,side=BOTTOM)
q_button = Button(main_window,width=15)
q_button["text"] = "Quit"
q_button.bind("<Button>",quit)
q_button.pack(side=LEFT)
# as per Michael:
# It appears that 'Text' references the unbinding of
#   of printable text
# Next, I would like to be able to 'unbind'
#   Non-printing keystrokes, like delete, backspace
#   and TAB
q_button.unbind_class('Text', '<Any-KeyPress>')
q_button.unbind_class('Text', '<Any-KeyRelease>')
##################################################
i_button = Button(main_window,width=15)
i_button["text"] = "Test"
i_button.bind("<Button>",test)
i_button.pack(side=LEFT)
##################################################
st = ScrolledText(text_frame ,background="white")
st.bind('<KeyPress>', add_a) # per Michael
st.pack()

main_window.mainloop()