mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-41425: Make tkinter doc example runnable (GH-21706)
Co-authored-by: Ankit Chandawala <achandaw@amazon.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
ecaf949cc4
commit
c36dbac588
2 changed files with 18 additions and 13 deletions
|
@ -541,31 +541,35 @@ the variable, with no further intervention on your part.
|
||||||
|
|
||||||
For example::
|
For example::
|
||||||
|
|
||||||
class App(Frame):
|
import tkinter as tk
|
||||||
def __init__(self, master=None):
|
|
||||||
|
class App(tk.Frame):
|
||||||
|
def __init__(self, master):
|
||||||
super().__init__(master)
|
super().__init__(master)
|
||||||
self.pack()
|
self.pack()
|
||||||
|
|
||||||
self.entrythingy = Entry()
|
self.entrythingy = tk.Entry()
|
||||||
self.entrythingy.pack()
|
self.entrythingy.pack()
|
||||||
|
|
||||||
# here is the application variable
|
# Create the application variable.
|
||||||
self.contents = StringVar()
|
self.contents = tk.StringVar()
|
||||||
# set it to some value
|
# Set it to some value.
|
||||||
self.contents.set("this is a variable")
|
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
|
self.entrythingy["textvariable"] = self.contents
|
||||||
|
|
||||||
# and here we get a callback when the user hits return.
|
# Define a callback for when the user hits return.
|
||||||
# we will have the program print out the value of the
|
# It prints the current value of the variable.
|
||||||
# application variable when the user hits return
|
|
||||||
self.entrythingy.bind('<Key-Return>',
|
self.entrythingy.bind('<Key-Return>',
|
||||||
self.print_contents)
|
self.print_contents)
|
||||||
|
|
||||||
def print_contents(self, event):
|
def print_contents(self, event):
|
||||||
print("hi. contents of entry is now ---->",
|
print("Hi. The current entry content is:",
|
||||||
self.contents.get())
|
self.contents.get())
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
myapp = App(root)
|
||||||
|
myapp.mainloop()
|
||||||
|
|
||||||
The Window Manager
|
The Window Manager
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make tkinter doc example runnable.
|
Loading…
Add table
Add a link
Reference in a new issue