blob: a1b13c34ce5d2e1ebf43f8e211027cde0c6b8905 [file] [log] [blame]
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +00001import os
2import sys
3from Tkinter import *
4
5
6class HelpWindow:
7
8 helpfile = "help.txt"
9 helptitle = "Help Window"
10
11 def __init__(self, root=None):
12 if not root:
13 import Tkinter
14 root = Tkinter._default_root
15 if root:
16 self.top = top = Toplevel(root)
17 else:
18 self.top = top = root = Tk()
19
20 helpfile = self.helpfile
21 if not os.path.exists(helpfile):
22 base = os.path.basename(self.helpfile)
23 for dir in sys.path:
24 fullname = os.path.join(dir, base)
25 if os.path.exists(fullname):
26 helpfile = fullname
27 break
28 try:
29 f = open(helpfile)
30 data = f.read()
31 f.close()
32 except IOError, msg:
33 data = "Can't open the help file (%s)" % `helpfile`
34
35 top.protocol("WM_DELETE_WINDOW", self.close_command)
36 top.wm_title(self.helptitle)
37
38 self.close_button = Button(top, text="close",
39 command=self.close_command)
40 self.close_button.pack(side="bottom")
41
42 self.vbar = vbar = Scrollbar(top, name="vbar")
43 self.text = text = Text(top)
44
45 vbar["command"] = text.yview
46 text["yscrollcommand"] = vbar.set
47
48 vbar.pack(side="right", fill="y")
49 text.pack(side="left", fill="both", expand=1)
50
51 text.insert("1.0", data)
52
53 text.config(state="disabled")
54 text.see("1.0")
55
56 def close_command(self):
57 self.top.destroy()
58
59
60def main():
61 h = HelpWindow()
62 h.top.mainloop()
63
64if __name__ == "__main__":
65 main()