4834_lecture_23_ho

4834_lecture_23_ho - EEL 4834: Lecture 23 EEL 4834: Lecture...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EEL 4834: Lecture 23 EEL 4834: Lecture 23 GUI Programming 2 Professor O. Boykin University of Florida, Department of Electrical and Computer Engineering October 22, 2009 EEL 4834: Lecture 23 Outline 1 Events 2 Layout and Appearance EEL 4834: Lecture 23 Events Events Consider the following events: user clicks a mouse button user releases a mouse button user presses a key How do we cause functions to be called when these things happen? EEL 4834: Lecture 23 Events Binding Events Suppose we want to change our previous GUI from: to: Note the equals button is no longer a button, instead we want to run the calculation when the enter (or return) key is pressed. EEL 4834: Lecture 23 Events The Binding Code We change: r entry = Entry(top, width=6, textvariable=r) r entry.pack(side= ’left’ ) s = StringVar() # variable to be attached to s label def comp s(): global s s.set( ’%g’ % math.sin(float(r.get()))) # construct string compute = Button(top, text= ’ equals ’ , command=comp s) to: r entry = Entry(top, width=6, textvariable=r) r entry.pack(side= ’left’ ) s = StringVar() # variable to be attached to s label def comp s(event): global s s.set( ’%g’ % math.sin(float(r.get()))) # construct string r entry.bind( ’ < Return > ’ , comp s) compute = Label(top, text= ’ equals ’ ) Note the callback function comp s takes an argument which is the event that triggered it. EEL 4834: Lecture 23 Events A Second Example: Closing with ‘q’ We could add an event handler for the root window: root = Tk() # root (main) window def quit(event): root.destroy() root.bind( ’ < q > ’ , quit) EEL 4834: Lecture 23 Events Binding In addition to binding keys, we can also bind mouse events:...
View Full Document

This note was uploaded on 02/11/2010 for the course EEL 4834 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 8

4834_lecture_23_ho - EEL 4834: Lecture 23 EEL 4834: Lecture...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online