From 5433db2f70caa1bbecb05960c1876707e9b5b8bd Mon Sep 17 00:00:00 2001 From: Ankit Chandawala Date: Mon, 3 Aug 2020 01:46:17 +0100 Subject: [PATCH 1/4] Fix example in tkinter documentation --- Doc/library/tkinter.rst | 10 +++++++--- .../Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index 2dc44ad36a7f73..a22250e90d4d95 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -542,16 +542,18 @@ the variable, with no further intervention on your part. For example:: - class App(Frame): + import tkinter as tk + + class App(tk.Frame): def __init__(self, master=None): super().__init__(master) self.pack() - self.entrythingy = Entry() + self.entrythingy = tk.Entry() self.entrythingy.pack() # here is the application variable - self.contents = StringVar() + self.contents = tk.StringVar() # set it to some value self.contents.set("this is a variable") # tell the entry widget to watch this variable @@ -567,6 +569,8 @@ For example:: print("hi. contents of entry is now ---->", self.contents.get()) + myapp = App() + myapp.mainloop() The Window Manager ^^^^^^^^^^^^^^^^^^ diff --git a/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst b/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst new file mode 100644 index 00000000000000..49a5fb871cb9c1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst @@ -0,0 +1 @@ +Fix example in tkinter documentation From f4eef263d4d26f4813e7d66299a564ca81bfa97b Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 2 Aug 2020 23:22:19 -0400 Subject: [PATCH 2/4] Polish the tkinter.rst example, including comments. --- Doc/library/tkinter.rst | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index a22250e90d4d95..0302ac66dffe48 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -542,35 +542,35 @@ the variable, with no further intervention on your part. For example:: - import tkinter as tk +import tkinter as tk - class App(tk.Frame): - def __init__(self, master=None): - super().__init__(master) - self.pack() +class App(tk.Frame): + def __init__(self, master): + super().__init__(master) + self.pack() - self.entrythingy = tk.Entry() - self.entrythingy.pack() + self.entrythingy = tk.Entry() + self.entrythingy.pack() - # here is the application variable - self.contents = tk.StringVar() - # set it to some value - self.contents.set("this is a variable") - # tell the entry widget to watch this variable - self.entrythingy["textvariable"] = self.contents + # Create the application variable. + self.contents = tk.StringVar() + # Set it to some value. + self.contents.set("this is a variable") + # Tell the entry widget to watch this variable. + self.entrythingy["textvariable"] = self.contents - # and here we get a callback when the user hits return. - # we will have the program print out the value of the - # application variable when the user hits return - self.entrythingy.bind('', - self.print_contents) + # Define a callback for when the user hits return. + # It prints the current value of the variable. + self.entrythingy.bind('', + self.print_contents) - def print_contents(self, event): - print("hi. contents of entry is now ---->", - self.contents.get()) + def print_contents(self, event): + print("Hi. The current entry content is:", + self.contents.get()) - myapp = App() - myapp.mainloop() +root = tk.Tk() +myapp = App(root) +myapp.mainloop() The Window Manager ^^^^^^^^^^^^^^^^^^ @@ -865,4 +865,4 @@ use raw reads or ``os.read(file.fileno(), maxbytecount)``. WRITABLE EXCEPTION - Constants used in the *mask* arguments. \ No newline at end of file + Constants used in the *mask* arguments. From ba4648da32a88ebda288bfee0729d8550aeac6eb Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 2 Aug 2020 23:28:21 -0400 Subject: [PATCH 3/4] Add 3-space .rst indent. I had to remove it to test the revised code. --- Doc/library/tkinter.rst | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index 0302ac66dffe48..14b9e434b0a3a1 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -542,35 +542,35 @@ the variable, with no further intervention on your part. For example:: -import tkinter as tk - -class App(tk.Frame): - def __init__(self, master): - super().__init__(master) - self.pack() - - self.entrythingy = tk.Entry() - self.entrythingy.pack() - - # Create the application variable. - self.contents = tk.StringVar() - # Set it to some value. - self.contents.set("this is a variable") - # Tell the entry widget to watch this variable. - self.entrythingy["textvariable"] = self.contents - - # Define a callback for when the user hits return. - # It prints the current value of the variable. - self.entrythingy.bind('', - self.print_contents) - - def print_contents(self, event): - print("Hi. The current entry content is:", - self.contents.get()) - -root = tk.Tk() -myapp = App(root) -myapp.mainloop() + import tkinter as tk + + class App(tk.Frame): + def __init__(self, master): + super().__init__(master) + self.pack() + + self.entrythingy = tk.Entry() + self.entrythingy.pack() + + # Create the application variable. + self.contents = tk.StringVar() + # Set it to some value. + self.contents.set("this is a variable") + # Tell the entry widget to watch this variable. + self.entrythingy["textvariable"] = self.contents + + # Define a callback for when the user hits return. + # It prints the current value of the variable. + self.entrythingy.bind('', + self.print_contents) + + def print_contents(self, event): + print("Hi. The current entry content is:", + self.contents.get()) + + root = tk.Tk() + myapp = App(root) + myapp.mainloop() The Window Manager ^^^^^^^^^^^^^^^^^^ From 81f40ea0f2134dd513885e3c6eb94602a61723d9 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 2 Aug 2020 23:30:26 -0400 Subject: [PATCH 4/4] Update 2020-08-03-01-59-48.bpo-41425.KJo6zF.rst --- .../next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst b/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst index 49a5fb871cb9c1..617df72faeb37f 100644 --- a/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst +++ b/Misc/NEWS.d/next/Library/2020-08-03-01-59-48.bpo-41425.KJo6zF.rst @@ -1 +1 @@ -Fix example in tkinter documentation +Make tkinter doc example runnable.