-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotepad--.py
More file actions
executable file
·43 lines (37 loc) · 1.12 KB
/
notepad--.py
File metadata and controls
executable file
·43 lines (37 loc) · 1.12 KB
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
#!/usr/bin/env python
"""Notepad-- : A very simple text editor."""
import sys
if sys.version_info < (3,):
import Tkinter as tk
import tkFileDialog as filedialog
else:
import tkinter as tk
from tkinter import filedialog
def create_gui(root):
"""Set up the GUI and functionality."""
root.title("Notepad--")
textbox = tk.Text(root)
textbox.pack(expand=True, fill=tk.BOTH)
# Functionality for opening and saving files.
def open_file():
"""Open a file"""
f = filedialog.askopenfile()
if f:
textbox.delete(1.0, tk.END)
textbox.insert(tk.END, f.read())
f.close()
def save_file():
"""Save a file"""
f = filedialog.asksaveasfile()
if f:
f.write(textbox.get(1.0, tk.END)[:-1])
f.close()
# Set up the command buttons
frame = tk.Frame(root)
frame.pack()
tk.Button(frame, text="Open", command=open_file).pack(side=tk.LEFT)
tk.Button(frame, text="Save", command=save_file).pack(side=tk.LEFT)
if __name__ == "__main__":
root = tk.Tk()
create_gui(root)
root.mainloop()