-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyPythonNote.py
More file actions
77 lines (61 loc) · 1.89 KB
/
MyPythonNote.py
File metadata and controls
77 lines (61 loc) · 1.89 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
import tkinter
from tkinter import *
from tkinter.filedialog import *
from tkinter import scrolledtext
def new_file():
text_area.delete(1.0, END)
def save_file():
f = asksaveasfilename(
initialfile='noname.txt',
defaultextension='.txt',
filetypes=[('Text Files', '.txt',)])
save_tmp = str(text_area.get(1.0, END))
with open(f, 'w', encoding='UTF-8') as file:
file.write(save_tmp + "\n")
def open_file():
f = askopenfilename(
initialdir='/',
title="Select a file",
filetypes=[('Text Files', '.txt'),
('Python Files', '.py')])
text_area.delete(1.0, END) # 기존 텍스트 지우기
with open(f, 'r', encoding='UTF-8') as file:
lines = file.readlines()
str = ''
for line in lines:
str += line + "\n"
text_area.pack()
text_area.insert(tkinter.CURRENT, str)
def info():
info_view = Toplevel(window)
info_view.geometry('300x50+350+400')
info_view.title('Maker: LGH')
lb = Label(info_view, text="널 위해 준비했어!!")
lb.pack()
window = Tk()
window.title('MyNotepad')
window.geometry('400x400+300+300')
window.resizable(0, 0)
# 메뉴프레임생성
menu = Menu(window)
# 첫번째 메뉴
menu_1 = Menu(menu, tearoff=0)
menu_1.add_command(label="New", command=new_file)
menu_1.add_command(label="Save", command=save_file)
menu_1.add_command(label="Open", command=open_file)
menu_1.add_separator()
menu_1.add_command(label="Close", command=window.destroy)
menu.add_cascade(label='File', menu=menu_1)
# 두번째 메뉴
menu_2 = Menu(menu, tearoff=0)
menu_2.add_command(label="Info", command=info)
menu.add_cascade(label='Help', menu=menu_2)
# 텍스트 추가하기
# text_area = Text(window)
text_area = scrolledtext.ScrolledText(window)
window.grid_rowconfigure(0, weight=1)
window.grid_columnconfigure(0, weight=1)
text_area.grid(sticky=N + E + S + W)
# 메뉴 본창에 붙이기
window.config(menu=menu)
window.mainloop()