-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.py
39 lines (28 loc) · 1.26 KB
/
examples.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
import tkinter as tk
class Examples(tk.Frame):
"""Widget that displays examples.txt."""
def __init__(self, master=None):
super().__init__(master)
self.create_widgets()
def create_widgets(self):
"""Creates the widgets of the examples pane."""
self.text = tk.Text(self, wrap=tk.NONE)
initial_text = """\
Examples
========
"""
self.text.insert(tk.END, initial_text)
with open("examples.txt", "r") as f:
self.text.insert(tk.END, f.read())
# create a vertical scrollbar
self.vscrollbar = tk.Scrollbar(self, orient=tk.VERTICAL, command=self.text.yview)
self.text.config(yscrollcommand=self.vscrollbar.set)
# create a horizontal scrollbar
self.hscrollbar = tk.Scrollbar(self, orient=tk.HORIZONTAL, command=self.text.xview)
self.text.config(xscrollcommand=self.hscrollbar.set)
self.vscrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.hscrollbar.pack(side=tk.BOTTOM, fill=tk.X)
self.text.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
self.text.config(state=tk.DISABLED)
self.text.config(font=("consolas", 12))
self.text.config(bg="#ffffe0") # yellowish paper-colored background color