Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 280aace

Browse files
committed
Issue #22053: Make help work, after previous patch for this issue disabled it
by removing global 'demo'. Refactor and remove duplicate code.
1 parent fea6a10 commit 280aace

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

Lib/turtledemo/__main__.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ def getExampleEntries():
2727
return [entry[:-3] for entry in os.listdir(demo_dir) if
2828
entry.endswith(".py") and entry[0] != '_']
2929

30-
def showDemoHelp():
31-
view_file(demo.root, "Help on turtleDemo",
32-
os.path.join(demo_dir, "demohelp.txt"))
33-
34-
def showAboutDemo():
35-
view_file(demo.root, "About turtleDemo",
36-
os.path.join(demo_dir, "about_turtledemo.txt"))
37-
38-
def showAboutTurtle():
39-
view_file(demo.root, "About the new turtle module.",
40-
os.path.join(demo_dir, "about_turtle.txt"))
30+
help_entries = ( # (help_label, help_file)
31+
('Turtledemo help', "demohelp.txt"),
32+
('About turtledemo', "about_turtledemo.txt"),
33+
('About turtle module', "about_turtle.txt"),
34+
)
4135

4236
class DemoWindow(object):
4337

@@ -177,12 +171,10 @@ def makeHelpMenu(self):
177171
CmdBtn.pack(side=LEFT, padx='2m')
178172
CmdBtn.menu = Menu(CmdBtn)
179173

180-
CmdBtn.menu.add_command(label='About turtle.py', font=menufont,
181-
command=showAboutTurtle)
182-
CmdBtn.menu.add_command(label='turtleDemo - Help', font=menufont,
183-
command=showDemoHelp)
184-
CmdBtn.menu.add_command(label='About turtleDemo', font=menufont,
185-
command=showAboutDemo)
174+
for help_label, help_file in help_entries:
175+
def show(help_label=help_label, help_file=help_file):
176+
view_file(self.root, help_label, os.path.join(demo_dir, help_file))
177+
CmdBtn.menu.add_command(label=help_label, font=menufont, command=show)
186178

187179
CmdBtn['menu'] = CmdBtn.menu
188180
return CmdBtn

0 commit comments

Comments
 (0)