Skip to content

Commit c36dbac

Browse files
nerandellAnkit Chandawalaterryjreedy
authored
bpo-41425: Make tkinter doc example runnable (GH-21706)
Co-authored-by: Ankit Chandawala <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent ecaf949 commit c36dbac

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Doc/library/tkinter.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,31 +541,35 @@ the variable, with no further intervention on your part.
541541

542542
For example::
543543

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):
546548
super().__init__(master)
547549
self.pack()
548550

549-
self.entrythingy = Entry()
551+
self.entrythingy = tk.Entry()
550552
self.entrythingy.pack()
551553

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.
555557
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.
557559
self.entrythingy["textvariable"] = self.contents
558560

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.
562563
self.entrythingy.bind('<Key-Return>',
563-
self.print_contents)
564+
self.print_contents)
564565

565566
def print_contents(self, event):
566-
print("hi. contents of entry is now ---->",
567+
print("Hi. The current entry content is:",
567568
self.contents.get())
568569

570+
root = tk.Tk()
571+
myapp = App(root)
572+
myapp.mainloop()
569573

570574
The Window Manager
571575
^^^^^^^^^^^^^^^^^^
@@ -860,4 +864,4 @@ use raw reads or ``os.read(file.fileno(), maxbytecount)``.
860864
WRITABLE
861865
EXCEPTION
862866

863-
Constants used in the *mask* arguments.
867+
Constants used in the *mask* arguments.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make tkinter doc example runnable.

0 commit comments

Comments
 (0)