@@ -541,31 +541,35 @@ the variable, with no further intervention on your part.
541
541
542
542
For example::
543
543
544
- class App(Frame):
545
- def __init__(self, master=None):
544
+ import tkinter as tk
545
+
546
+ class App(tk.Frame):
547
+ def __init__(self, master):
546
548
super().__init__(master)
547
549
self.pack()
548
550
549
- self.entrythingy = Entry()
551
+ self.entrythingy = tk. Entry()
550
552
self.entrythingy.pack()
551
553
552
- # here is the application variable
553
- self.contents = StringVar()
554
- # set it to some value
554
+ # Create the application variable.
555
+ self.contents = tk. StringVar()
556
+ # Set it to some value.
555
557
self.contents.set("this is a variable")
556
- # tell the entry widget to watch this variable
558
+ # Tell the entry widget to watch this variable.
557
559
self.entrythingy["textvariable"] = self.contents
558
560
559
- # and here we get a callback when the user hits return.
560
- # we will have the program print out the value of the
561
- # application variable when the user hits return
561
+ # Define a callback for when the user hits return.
562
+ # It prints the current value of the variable.
562
563
self.entrythingy.bind('<Key-Return>',
563
- self.print_contents)
564
+ self.print_contents)
564
565
565
566
def print_contents(self, event):
566
- print("hi. contents of entry is now ----> ",
567
+ print("Hi. The current entry content is: ",
567
568
self.contents.get())
568
569
570
+ root = tk.Tk()
571
+ myapp = App(root)
572
+ myapp.mainloop()
569
573
570
574
The Window Manager
571
575
^^^^^^^^^^^^^^^^^^
0 commit comments