Entry components and event binding demonstration. : Key Event « Tkinker « Python Tutorial






Entry components and event binding demonstration.
from Tkinter import *
from tkMessageBox import *

class EntryDemo( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( "Testing Entry Components" )
      self.master.geometry( "325x100" )

      self.frame1 = Frame( self )
      self.frame1.pack( pady = 5 )
      
      self.text1 = Entry( self.frame1, name = "text1" )

      self.text1.bind( "<Return>", self.showContents )
      self.text1.pack( side = LEFT, padx = 5 )

   def showContents( self, event ):
      theName = event.widget.winfo_name()

      theContents = event.widget.get()
      showinfo( "Message", theName + ": " + theContents )

EntryDemo().mainloop()








18.16.Key Event
18.16.1.Get key codeGet key code
18.16.2.Up arrow keyUp arrow key
18.16.3.Enter key eventEnter key event
18.16.4.Bind key action to buttonBind key action to button
18.16.5.Entry components and event binding demonstration.Entry components and event binding demonstration.
18.16.6.Binding keys to keyboard events.Binding keys to keyboard events.