Lv.1
我......我是个人(滑稽)
签名:正在编写 python 前端
在 【有大佬吗】python菜鸟求助 中回复
import tkinter
import tkinter.messagebox as m
m.showwarning('标题','你的电脑要炸了')2020-07-01T07:17:00 点赞:0
在 编程猫丨第一届Python选拔赛(非官方举办) 中回复
from tkinter import *
import tkinter.filedialog as f
import tkinter.colorchooser as c
import tkinter.messagebox as m
import tkinter.simpledialog as s
import sys
import os
import time
import calendar
str9=time.localtime(time.time())
str5=str(time.ctime())
root = Tk()
root.title('记事本')
root.width=400
root.weight=400
menubar = Menu(root)
text1=Text(root)
text1.pack(fill=BOTH,expand=True)
def ac():
a7 = s.askinteger(title='年份询问',prompt='请输入日历的年份:', initialvalue=str9.tm_year)
a8 = s.askinteger(title='月份询问',prompt='请输入日历的月份:', initialvalue=str9.tm_mon)
cal = calendar.month(a7,a8)
text1.insert(0.0,cal)
def at():
text1.insert(0.0,str5)
def DN():
text1.insert(0.0,os.getcwd())
def New():
text1.delete('1.0',END)
def save():
str1=text1.get(1.0,END)
rs=f.asksaveasfilename(title='保存',filetype=[('python源文件','.py'),('文本','txt')])
ff=open(rs,'w',encoding='utf-8')
ff.write(str1)
ff.close()
def window():
text1.delete('1.0',END)
rs=f.askopenfilename(title='打开',filetype=[('python源文件','.py'),('文本','txt')])
try:
ff=open(rs,'r',encoding='utf-8')
str1=ff.read()
text1.insert(0.0,str1)
except:
pass
finally:
ff.close()
def Quit():
quit()
sys.exit()
def textcolor():
r1,r2=c.askcolor(title='字体颜色',color='red')
text1.config(fg=r2)
def BGcolor():
r1,r2=c.askcolor(title='页面颜色',color='red')
text1.config(bg=r2)
def texthelp():
m.showinfo(title='关于',message='这是一个关于记录时间的程序!')
def about():
r3=s.askstring(title='帮助',prompt='具体请见官方文档!其余,请问您有什么问题吗?')
def change():
str1=text1.get(1.0,END)
r4=s.askstring(title='被替换',prompt='请输入要替换的字符:')
r5=s.askstring(title='替换项',prompt='请输入要把他替换的项:')
str2=''
for x in str1:
if str(r4) == x:
str2 += str(r5)
else:
str2 += x
text1.delete('1.0',END)
text1.insert(0.0,str2)
filemenu=Menu(menubar,tearoff=False)
filemenu.a喵_command(label='新建',command=New)
filemenu.a喵_command(label='打开',command=window)
filemenu.a喵_separator()
filemenu.a喵_command(label='保存',command=save)
filemenu.a喵_command(label='退出',command=Quit)
menubar.a喵_cascade(label='文件',menu=filemenu)
root.config(menu=menubar)
Runmenu=Menu(menubar,tearoff=False)
Runmenu.a喵_command(label='字体颜色',command=textcolor)
Runmenu.a喵_separator()
Runmenu.a喵_command(label='页面颜色',command=BGcolor)
menubar.a喵_cascade(label='个性化',menu=Runmenu)
root.config(menu=menubar)
Windowmenu=Menu(menubar,tearoff=False)
Windowmenu.a喵_command(label='帮助',command=about)
Windowmenu.a喵_command(label='关于',command=texthelp)
menubar.a喵_cascade(label='关于',menu=Windowmenu)
root.config(menu=menubar)
Change=Menu(menubar,tearoff=False)
Change.a喵_command(label='替换',command=change)
menubar.a喵_cascade(label='替换',menu=Change)
root.config(menu=menubar)
Time=Menu(menubar,tearoff=False)
Time.a喵_command(label='时间',command=at)
Time.a喵_command(label='日历',command=ac)
menubar.a喵_cascade(label='添加',menu=Time)
root.config(menu=menubar)
mainloop()
2020-07-02T07:54:51 点赞:0