-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextfile_window.py
75 lines (53 loc) · 2.19 KB
/
textfile_window.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
"""
This file is part of Sprout.
Sprout is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Sprout is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Sprout. If not, see <http://www.gnu.org/licenses/>.
Copyright 2013, Michihiro Takami, Hyosun Kim, Jennifer Karr
All rights reserved.
Contact: Jennifer Karr ([email protected])
"""
from Tkinter import *
class textfile_window(Frame):
def __init__(self,title,textfile,master=None):
Frame.__init__(self,master)
"""
Class to show the contents of a text file, with a quit button and scrollbar.
Two parameters, the title, and the name of the file.
To call: self.helpwin=textfile_window(title,textfile)
self.helpwin.pack(side=TOP,anchor=W,fill=X)
self.helpwin.update()
"""
##CREATE WINDOW, ADD CLOSE BUTTON
top=Toplevel(self)
top.title(title)
fm=Frame(top, relief=RAISED, bd=1)
mb2=Button(fm,text='Close',command=self.destroy).pack(side=LEFT,anchor=W)
fm.pack(side=TOP,anchor=W,fill=X)
##CREATE THE TEXT WINDOW AND ADD THE SCROLLBAR
fm=Frame(top, relief=RAISED, bd=1)
self.text=Text(fm,height=30,width=100)
self.scroll=Scrollbar(fm)
self.text.focus_set()
self.scroll.pack(side=RIGHT,fill=Y)
self.text.pack(side=LEFT,fill=Y)
self.scroll.config(command=self.text.yview)
self.text.config(yscrollcommand=self.scroll.set)
fm.pack(side=TOP,anchor=W,fill=X)
##OPEN THE TEXT FILE AND DISPLAY
try:
myFile=open(textfile,'r')
myText= myFile.read()
myFile.close()
except:
myText="Cannot Find File "+textfile+"\n"
self.text.insert(0.0,myText)
##-----------------------------------------------------------------------