Skip to content

bpo-41425: Make tkinter doc example runnable #21706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Doc/library/tkinter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -542,31 +542,35 @@ the variable, with no further intervention on your part.

For example::

class App(Frame):
def __init__(self, master=None):
import tkinter as tk

class App(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.pack()

self.entrythingy = Entry()
self.entrythingy = tk.Entry()
self.entrythingy.pack()

# here is the application variable
self.contents = StringVar()
# set it to some value
# 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
# 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
# Define a callback for when the user hits return.
# It prints the current value of the variable.
self.entrythingy.bind('<Key-Return>',
self.print_contents)
self.print_contents)

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

root = tk.Tk()
myapp = App(root)
myapp.mainloop()

The Window Manager
^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -861,4 +865,4 @@ use raw reads or ``os.read(file.fileno(), maxbytecount)``.
WRITABLE
EXCEPTION

Constants used in the *mask* arguments.
Constants used in the *mask* arguments.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make tkinter doc example runnable.