不多说,上代码:
from tkinter import *
from tkinter import messagebox
from playsound import *
from threading import *
from linecache import *
from random import *
CreateButton = locals()
putcur=0
code="""
from math import *
global num
num="""
def curset(n,var2):
if n>=41:var2.set("文本已占满!请清空!")
else:var2.set("当前操作位数:"+str(n))
def puttext(var,text,TF_append):
global putcur
Restr = ""
line = list(var.get())
long = len(line)
if TF_append == 0: line.insert(putcur+long,text)
else: del line[putcur+long-1]
Restr = ''.join(line)
return Restr
def ErrMe(title,text):
messagebox.showerror(title,text,type="ok")
def run(var):
t = "错误"
try:
exec(code+var.get())
return num
except EOFError:
ErrMe("文件读取错误!","你是不是把里面的文件删了?")
return t
except SyntaxError:
ErrMe("识别错误","你是不是漏加或多加了一个括号?\n还是写了个令程序迷惑的表达式?")
return t
except TypeError:
ErrMe("格式错误","少加或多加了几个参数!\n或是给错了不符合要求的值!")
return t
except ZeroDivisionError:
return '无限大'
except NameError:
ErrMe("变量错误","这里不能定义变量!")
return t
except ValueError:
ErrMe("赋值错误","认真看一下'帮助'中的'查看拓展'再重新赋值!")
return t
def opensound():
playsound("resoures\\Windows_open.wav")
def in_and_out(n, var,var2,root,telab):
global putcur
if n == 1:
var.set("")
putcur = 0
curset(len(var.get())+putcur,var2)
elif n == 23:
if var.get() == "":
var.set("")
else:
var.set(run(var))
curset(len(var.get())+putcur,var2)
elif n==27:
try:
text = getline('resoures\\box.txt', n).strip('\n')
var.set(puttext(var,text,1))
curset(len(var.get())+putcur,var2)
except IndexError:
putcur = 0
var2.set("当前操作位数:"+str(len(var.get())))
elif n==28:
CreateHelp(root,telab)
elif n==29:
putcur = putcur - 1
curset(len(var.get())+putcur,var2)
elif n==30:
putcur = putcur + 1
curset(len(var.get())+putcur,var2)
else:
text = getline('resoures\\box.txt', n).strip('\n')
var.set(puttext(var,text,0))
curset(len(var.get())+putcur,var2)
def xput(wrv,var,var2):
global putcur
var.set(puttext(var,wrv.get(),0))
wrv.set("")
curset(len(var.get())+putcur,var2)
def main(root):
var = StringVar()
var2 = StringVar()
wrv = StringVar()
var.set("")
wrv.set("")
root.title("我的计算器")
root.iconbitmap("resoures\\dkss.ico")
root.geometry("640x386")
root.geometry("+320+160")
root.resizable(0, 0)
root.config(cursor = "@AppStarting.ani")
photo = PhotoImage(file="resoures\\bg.gif")
bg = Canvas(root, width=640, height=386, highlightthickness=0)
bg.create_image(320, 193, image=photo)
bg.pack()
telab = Label(root, textvariable=var, highlightthickness=2, anchor=NW,cursor="@IBeam.ani",relief=SUNKEN)
telab.pack()
curlab = Label(root,textvariable=var2,anchor=NW,cursor="@undertext1.ani",relief=RIDGE)
curlab.pack()
stick = Entry(root,textvariable=wrv,cursor="@entry1.ani")
stick.pack()
click = Button(root,text="粘贴",cursor="@click.ani",fg="DarkBlue",command=lambda:xput(wrv,var,var2))
click.pack()
CreateButton['cw' + str(1)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 1).strip('\n'), command= lambda: in_and_out(1, var,var2,root,telab))
CreateButton['cw' + str(2)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 2).strip('\n'), command= lambda: in_and_out(2, var,var2,root,telab))
CreateButton['cw' + str(3)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 3).strip('\n'), command= lambda: in_and_out(3, var,var2,root,telab))
CreateButton['cw' + str(4)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 4).strip('\n'), command= lambda: in_and_out(4, var,var2,root,telab))
CreateButton['cw' + str(5)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 5).strip('\n'), command= lambda: in_and_out(5, var,var2,root,telab))
CreateButton['cw' + str(6)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 6).strip('\n'), command= lambda: in_and_out(6, var,var2,root,telab))
CreateButton['cw' + str(7)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 7).strip('\n'), command= lambda: in_and_out(7, var,var2,root,telab))
CreateButton['cw' + str(8)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 8).strip('\n'), command= lambda: in_and_out(8, var,var2,root,telab))
CreateButton['cw' + str(9)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 9).strip('\n'), command= lambda: in_and_out(9, var,var2,root,telab))
CreateButton['cw' + str(10)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 10).strip('\n'),command=lambda: in_and_out(10, var,var2,root,telab))
CreateButton['cw' + str(11)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 11).strip('\n'),command=lambda: in_and_out(11, var,var2,root,telab))
CreateButton['cw' + str(12)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 12).strip('\n'),command=lambda: in_and_out(12, var,var2,root,telab))
CreateButton['cw' + str(13)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 13).strip('\n'),command=lambda: in_and_out(13, var,var2,root,telab))
CreateButton['cw' + str(14)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 14).strip('\n'),command=lambda: in_and_out(14, var,var2,root,telab))
CreateButton['cw' + str(15)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 15).strip('\n'),command=lambda: in_and_out(15, var,var2,root,telab))
CreateButton['cw' + str(16)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 16).strip('\n'),command=lambda: in_and_out(16, var,var2,root,telab))
CreateButton['cw' + str(17)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 17).strip('\n'),command=lambda: in_and_out(17, var,var2,root,telab))
CreateButton['cw' + str(18)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 18).strip('\n'),command=lambda: in_and_out(18, var,var2,root,telab))
CreateButton['cw' + str(19)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 19).strip('\n'),command=lambda: in_and_out(19, var,var2,root,telab))
CreateButton['cw' + str(20)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 20).strip('\n'),command=lambda: in_and_out(20, var,var2,root,telab))
CreateButton['cw' + str(21)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 21).strip('\n'),command=lambda: in_and_out(21, var,var2,root,telab))
CreateButton['cw' + str(22)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 22).strip('\n'),command=lambda: in_and_out(22, var,var2,root,telab))
CreateButton['cw' + str(23)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 23).strip('\n'),command=lambda: in_and_out(23, var,var2,root,telab))
CreateButton['cw' + str(24)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 24).strip('\n'),command=lambda: in_and_out(24, var,var2,root,telab))
CreateButton['cw' + str(25)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 25).strip('\n'),command=lambda: in_and_out(25, var,var2,root,telab))
CreateButton['cw' + str(26)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 26).strip('\n'),command=lambda: in_and_out(26, var,var2,root,telab))
CreateButton['cw' + str(27)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 27).strip('\n'),command=lambda: in_and_out(27, var,var2,root,telab))
CreateButton['cw' + str(28)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 28).strip('\n'),command=lambda: in_and_out(28, var,var2,root,telab))
CreateButton['cw' + str(29)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 29).strip('\n'),command=lambda: in_and_out(29, var,var2,root,telab))
CreateButton['cw' + str(30)] = Button(root, width=7, height=2, text=getline('resoures\\text.txt', 30).strip('\n'),command=lambda: in_and_out(30, var,var2,root,telab))
for i in range(1,31):
if i==28:CreateButton['cw' + str(i)].config(cursor="@Help.ani")
else:CreateButton['cw' + str(i)].config(cursor="@Arrow.ani")
CreateButton['cw'+str(i)].config(relief=GROOVE)
CreateButton['cw' + str(i)].pack()
bg.create_window(462, 25, width=294, window=telab)
for i in range(1,31):
bg.create_window(344 + ((i - 1) % 5) * 59, 75 + ((i - 1) // 5) * 47,window=CreateButton['cw' + str(i)])
bg.create_window(550,360 ,width=120, window=curlab)
bg.create_window(375,360 ,width=120, window=stick)
bg.create_window(462,360 ,height=24, window=click)
root.mainloop()
def change(childvar):
n = randint(1,57)
if n%2==1:childvar.set(getline("resoures\\tips.txt",n)+getline("resoures\\tips.txt",n+1).strip('\n'))
else:childvar.set(getline("resoures\\tips.txt",n-1)+getline("resoures\\tips.txt",n).strip('\n'))
def onclose(root,childroot,telab):
global CreateButton
childroot.destroy()
root.config(cursor = "@AppStarting.ani")
root.title("我的计算器")
telab.config(cursor="@IBeam.ani")
for i in range(1,31):
if i==28:CreateButton['cw'+str(i)].config(cursor="@Help.ani")
else:CreateButton['cw'+str(i)].config(cursor="@Arrow.ani")
def anotherclose(childroot,ccroot,l1,l2,b1,b2):
ccroot.destroy()
childroot.config(cursor = "@wait.ani")
childroot.title("帮助")
l2.config(cursor="@undertext2.ani")
b1.config(cursor="@b1.ani")
b2.config(cursor="@b2.ani")
def CreateHelp(root,telab):
global CreateButton
childvar = StringVar()
childvar.set(getline("resoures\\tips.txt",1)+getline("resoures\\tips.txt",2).strip('\n'))
childroot = Toplevel()
childroot.geometry("545x600")
childroot.geometry("+80+30")
childroot.title("帮助")
childroot.resizable(0,0)
childroot.iconbitmap("resoures\\childroot.ico")
childroot.config(cursor="@wait.ani")
root.config(cursor = "@NO.ani")
root.title("此窗口已被禁用")
telab.config(cursor="@NO2.ani")
for i in range(1,31):
if i==28:CreateButton['cw'+str(i)].config(cursor="@wait.ani")
else:CreateButton['cw'+str(i)].config(cursor="@hand.ani")
l1 = Label(childroot,image=photoc)
l1.pack()
l2 = Label(childroot,height=20,width=50,textvariable=childvar,relief=GROOVE,cursor="@undertext2.ani",fg="Purple")
l2.pack(side=LEFT)
b1 = Button(childroot,width=12,height=2,text="刷新",cursor="@b1.ani",fg="OrangeRed",command=lambda:change(childvar))
b1.pack(side=LEFT)
b2 = Button(childroot,width=12,height=2,text="查看拓展",cursor="@b2.ani",fg="DeepSkyblue",command=lambda:loadtk(childroot,l1,l2,b1,b2))
b2.pack(side=RIGHT)
childroot.grab_set()
childroot.protocol('WM_DELETE_WINDOW',lambda:onclose(root,childroot,telab))
def loadtk(childroot,l1,l2,b1,b2):
childroot.title("此窗口已被禁用")
ccroot = Toplevel()
ccroot.geometry("599x500")
ccroot.title("拓展库大全")
ccroot.iconbitmap("resoures\\ccroot.ico")
ccroot.config(cursor="@ccroot.ani")
childroot.config(cursor="@crstop.ani")
l2.config(cursor="@t1wait.ani")
Label(ccroot,image=photoj,relief=RIDGE).pack(side=LEFT)
Label(ccroot,image=photox,relief=RIDGE,cursor="@VX.ani").pack(side=TOP)
Label(ccroot,image=photodl,relief=RIDGE,cursor="@getmy.ani").pack()
Label(ccroot,text="制作不易,赏点钱吧!\n光标资源来自大佬 '猫知道' \n致此鸣谢",fg='blue',relief=SUNKEN,width=99,height=30).pack()
b1.config(cursor="@Notallow.ani")
b2.config(cursor="@ccroot.ani")
ccroot.grab_set()
ccroot.protocol('WM_DELETE_WINDOW',lambda:anotherclose(childroot,ccroot,l1,l2,b1,b2))
if __name__ == "__main__":
thread = Thread(target=opensound)
thread.start()
root = Tk()
photoc = PhotoImage(file="resoures\\Help.gif")
photoj = PhotoImage(file="resoures\\load.gif")
photox = PhotoImage(file="resoures\\load1.gif")
photodl = PhotoImage(file="resoures\\QAQ.gif")
main(root)
thread.join()
playsound("resoures\\Windows_close.wav")
点我传送 密码:dgaf
|