python3实现记事本功能

-*-encoding:utf8

from tkinter import *
import time
import os;
import sys;
import imp

reload sys

imp.reload(sys);

设置系统的默认编码为utf8

root = Tk()

text1 = Text(root,width=120,height=40)

INSERT索引表示在光标处插入

text1.insert(INSERT,’I Love’)

END索引号表示在最后插入

text1.insert(END,’ you’)
text1.pack()

def saveClick():
print(“save here”)
path=os.getcwd() + ‘/hostb’
with open(path, ‘a+’) as fb:
fb.write(text1.get(1.0, END))

b1 = Button(root, text=’save’, command=saveClick)
text1.window_create(INSERT, window=b1)
b1.pack()

def exitClick():
print(“exit here”)
root.destroy()

b2 = Button(root, text=’exit’, command=exitClick)
text1.window_create(INSERT, window=b2)
b2.pack()
root.mainloop()

你可能感兴趣的:(python)