aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/idlelib/textView.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/textView.py')
-rw-r--r--Lib/idlelib/textView.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/idlelib/textView.py b/Lib/idlelib/textView.py
index 8937c17b6c4..1eaa4649edf 100644
--- a/Lib/idlelib/textView.py
+++ b/Lib/idlelib/textView.py
@@ -2,8 +2,8 @@
"""
-from Tkinter import *
-import tkMessageBox
+from tkinter import *
+import tkinter.messagebox as tkMessageBox
class TextViewer(Toplevel):
"""A simple text viewer dialog for IDLE
@@ -64,18 +64,15 @@ def view_text(parent, title, text, modal=True):
def view_file(parent, title, filename, encoding=None, modal=True):
try:
- if encoding:
- import codecs
- textFile = codecs.open(filename, 'r')
- else:
- textFile = open(filename, 'r')
+ with open(filename, 'r', encoding=encoding) as file:
+ contents = file.read()
except IOError:
- import tkMessageBox
+ import tkinter.messagebox as tkMessageBox
tkMessageBox.showerror(title='File Load Error',
message='Unable to load file %r .' % filename,
parent=parent)
else:
- return view_text(parent, title, textFile.read(), modal)
+ return view_text(parent, title, contents, modal)
if __name__ == '__main__':