Kaydet (Commit) ccf03a1c authored tarafından Éric Araujo's avatar Éric Araujo

Fix resource warning when looking at turtledemo’s help (#12295)

üst 2ffea0e8
...@@ -62,14 +62,15 @@ def view_text(parent, title, text): ...@@ -62,14 +62,15 @@ def view_text(parent, title, text):
def view_file(parent, title, filename, encoding=None): def view_file(parent, title, filename, encoding=None):
try: try:
textFile = open(filename, 'r', encoding=encoding) with open(filename, 'r', encoding=encoding) as file:
contents = file.read()
except IOError: except IOError:
import tkinter.messagebox as tkMessageBox import tkinter.messagebox as tkMessageBox
tkMessageBox.showerror(title='File Load Error', tkMessageBox.showerror(title='File Load Error',
message='Unable to load file %r .' % filename, message='Unable to load file %r .' % filename,
parent=parent) parent=parent)
else: else:
return view_text(parent, title, textFile.read()) return view_text(parent, title, contents)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment