-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathfile_reader.py
More file actions
25 lines (21 loc) · 792 Bytes
/
Copy pathfile_reader.py
File metadata and controls
25 lines (21 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
import os, tkinter
def display(filename):
if not (os.path.exists(filename) and not os.path.isdir(filename)):
content.set(filename+": No such file")
top.title(main_title+" - "+filename+": No such file")
return
with open(filename) as f:
content.set(f.read())
top.title(main_title+" - "+filename)
top = tkinter.Tk()
main_title = "File Reader"
top.title(main_title)
content = tkinter.StringVar()
filename = tkinter.StringVar()
text_label = tkinter.Label(top, textvariable=content, justify=tkinter.LEFT, anchor=tkinter.W)
text_label.pack(fill='both')
entry_field = tkinter.Entry(top, width=50, textvariable=filename)
entry_field.bind("<Return>", lambda event: display(filename.get()))
entry_field.pack()
tkinter.mainloop()