from tkinter import *
t = Tk()
from tkinter.scrolledtext import ScrolledText as st
from tkinter.ttk import Combobox as cb
from tkinter.filedialog import asksaveasfilename as savea, askopenfilename as openf
t.wm_title('tkinter记事本')
s = st(t,font=('微软雅黑',12))
s.pack()
se = StringVar(t)
l = ['微软雅黑','consolas','Comic Sans MS','xumin']
k = []
for i in range(99):
k.append(i)
def cbs(oxygen):
s.configure(font=(c.get(),12))
def funct(oxygen):
s.configure(font=(c.get(),e.get()))
def huanyuan(oxygen):
s.configure(font=('微软雅黑',12))
def saves(funcs):
b = s.get(1.0,'end')
j = savea()
v = open(j,'w')
v.write(b)
v.close()
def openi(funcs):
j = openf()
v = open(j)
a = v.read()
v.close()
s.delete(1.0,'end')
s.insert('end',a)
c = cb(t,textvariable=se)
c.pack()
c['value'] = l
e = cb(t,textvariable=se)
e.pack()
e['value'] = k
c.bind('<<ComboboxSelected>>',cbs)
e.bind('<<ComboboxSelected>>',funct)
t.bind('<Control-z>',huanyuan)
t.bind('<Control-s>',saves)
t.bind('<Control-o>',openi)
t.mainloop()
记事本 & 打开文件
最新推荐文章于 2024-03-12 11:06:41 发布