-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathnotepad_function.py
More file actions
83 lines (63 loc) · 1.99 KB
/
notepad_function.py
File metadata and controls
83 lines (63 loc) · 1.99 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
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
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#
# modifications for: http://codeshot.in/pythongui/notepad.php
#
# FB: https://www.facebook.com/groups/learnpython.org/permalink/1180950268636255/
#
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
# --- constants ---
# empty
# --- classes ---
# empty
# --- functions ---
def dummy():
messagebox.showinfo("UPS!", "Function not implemented.")
def open_command():
file_ = filedialog.askopenfile(mode="r")
if file_:
content = file_.read()
text.insert("1.0", content)
file_.close()
def save_command():
file_ = filedialog.asksaveasfile(mode="w")
if file_:
content = text.get("1.0", tk.END+"-1c") # do we need "-1c" ???
file_.write(content)
file_.close()
def exit_command():
if messagebox.askokcancel("Quit", "Do you really want to quit?"):
master.destroy()
def about_command():
messagebox.showinfo("About", "Text Editor Version 1.0.0 \nCopyright 2016 \nCreator : Abhishek Singh")
# --- main ---
master = tk.Tk()
master.title("Text Editor")
# add a text box
text = tk.Text(master)
text.pack()
# menus
menu = tk.Menu(master)
master.config(menu=menu)
# file menu
file_menu = tk.Menu(menu)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Open File", command=open_command)
file_menu.add_command(label="Save As", command=save_command)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=exit_command)
# edit menu
edit_menu = tk.Menu(menu)
menu.add_cascade(label="Edit", menu=edit_menu)
edit_menu.add_command(label="Undo", command=dummy)
edit_menu.add_command(label="Redo", command=dummy)
edit_menu.add_command(label="Cut", command=dummy)
edit_menu.add_command(label="Copy", command=dummy)
edit_menu.add_command(label="Paste", command=dummy)
# help menu
help_menu = tk.Menu(menu)
menu.add_cascade(label="Help", menu=help_menu)
help_menu.add_command(label="About", command=about_command)
# start the engine :)
master.mainloop()