import tkinter
from tkinter import *
from tkinter import messagebox
root = tkinter.Tk()
root.geometry("450x500+200+200")
root.resizable(0,0)
root.title("Calculator")
val = ""
A = 0
operator = ""
def entered(event):
btnc.config(bg="#ff4117")
def left(event):
btnc.config(bg="#fc876d")
def entered_(event):
btnx.config(bg="#ffd500")
def left_(event):
btnx.config(bg="#faed5f")
def btn_1_isclicked():
global val
val = val + "1"
data.set(val)
def btn_2_isclicked():
global val
val = val + "2"
data.set(val)
def btn_3_isclicked():
global val
val = val + "3"
data.set(val)
def btn_4_isclicked():
global val
val = val + "4"
data.set(val)
def btn_5_isclicked():
global val
val = val + "5"
data.set(val)
def btn_6_isclicked():
global val
val = val + "6"
data.set(val)
def btn_7_isclicked():
global val
val = val + "7"
data.set(val)
def btn_8_isclicked():
global val
val = val + "8"
data.set(val)
def btn_9_isclicked():
global val
val = val + "9"
data.set(val)
def btn_0_isclicked():
global val
val = val + "0"
data.set(val)
def btn_dot_isclicked():
global val
val = val + "."
data.set(val)
def btn_plus_clicked():
global A
global operator,val
A = float(val)
operator = "+"
val = val + "+"
data.set(val)
def btn_minus_clicked():
global A
global operator,val
A = float(val)
operator = "-"
val = val + "-"
data.set(val)
def btn_mult_clicked():
global A
global operator,val
A = float(val)
operator = "*"
val = val + "*"
data.set(val)
def btn_div_clicked():
global A
global operator,val
A = float(val)
operator = "/"
val = val + "/"
data.set(val)
def btn_exp_clicked():
global A
global operator,val
A = float(val)
operator = "^"
val = val + "^"
data.set(val)
def btn_c_pressed():
global A,operator,val
val = ""
A = 0
operator = ""
data.set(val)
def btn_x_pressed():
global A,operator,val
v = val[-1]
val = val[:len(val)-1]
if v in ['+','-','*','/']:
operator=""
operator = ""
data.set(val)
def result():
global A,operator,val
val2 = val
if operator == "+":
x = float((val2.split("+")[1]))
C = A + x
val = str(C)
data.set(val)
elif operator == "-":
x = float((val2.split("-")[1]))
C = A - x
val = str(C)
data.set(val)
elif operator == "*":
x = float((val2.split("*")[1]))
C = A * x
val = str(C)
data.set(val)
elif operator == "/":
x = float((val2.split("/")[1]))
if x == 0:
messagebox.showerror("Error", "Division By 0 Not Supported")
A = ""
val = ""
data.set(val)
else:
C = A / x
data.set(C)
elif operator == "^":
x = float((val2.split("^")[1]))
C = A ** x
val = str(C)
data.set(val)
else:
if '+' in val2 or '-' in val2 or '*' in val2 or '/' in val2 or '^' in val2:
return
x=float(val2)
C = x * x
val = str(C)
data.set(val)
data = StringVar()
lbl = Label(
root,
text = "Label",
anchor = SE,
font = ("Verdana", 20),
textvariable = data,
background = "#ffffff",
fg = "#000000",
)
lbl.pack(expand = True, fill = "both")
btnrow0 = Frame(root)
btnrow0.pack(expand = True, fill = "both")
btnrow1 = Frame(root)
btnrow1.pack(expand = True, fill = "both")
btnrow2 = Frame(root)
btnrow2.pack(expand = True, fill = "both")
btnrow3 = Frame(root)
btnrow3.pack(expand = True, fill = "both")
btnrow4 = Frame(root)
btnrow4.pack(expand = True, fill = "both")
btnc = Button(
btnrow0,
text = "C",
font = ("Verdana", 22),
bg = "#fc876d",
relief = GROOVE,
border = 0,
command = btn_c_pressed,
)
btnc.pack(side = LEFT, expand = True, fill = "both",)
btnc.bind("<Enter>",entered)
btnc.bind("<Leave>", left)
btnx = Button(
btnrow0,
text = "Del",
font = ("Verdana", 22),
bg="#faed5f",
relief = GROOVE,
border = 0,
command = btn_x_pressed,
)
btnx.pack(side = LEFT, expand = True, fill = "both",)
btnx.bind("<Enter>",entered_)
btnx.bind("<Leave>", left_)
btnpower = Button(
btnrow0,
text = "EXP",
font = ("Verdana", 22),
bg = "Red",
relief = GROOVE,
border = 0,
command = btn_exp_clicked,
)
btnpower.pack(side = LEFT, expand = True, fill = "both",)
btnsq = Button(
btnrow0,
text = "Sq",
font = ("Verdana", 22),
bg="green",
relief = GROOVE,
border = 0,
command = result,
)
btnsq.pack(side = LEFT, expand = True, fill = "both",)
btn1 = Button(
btnrow1,
text = "1",
font = ("Verdana", 22),
bg = "#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_1_isclicked,
)
btn1.pack(side = LEFT, expand = True, fill = "both",)
btn2 = Button(
btnrow1,
text = "2",
font = ("Verdana", 22),
bg = "#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_2_isclicked,
)
btn2.pack(side = LEFT, expand = True, fill = "both",)
btn3 = Button(
btnrow1,
text = "3",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_3_isclicked,
)
btn3.pack(side = LEFT, expand = True, fill = "both",)
btnplus = Button(
btnrow1,
text = "+",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_plus_clicked,
)
btnplus.pack(side = LEFT, expand = True, fill = "both",)
btn4 = Button(
btnrow2,
text = "4",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_4_isclicked,
)
btn4.pack(side = LEFT, expand = True, fill = "both",)
btn5 = Button(
btnrow2,
text = "5",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_5_isclicked,
)
btn5.pack(side = LEFT, expand = True, fill = "both",)
btn6 = Button(
btnrow2,
text = "6",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_6_isclicked,
)
btn6.pack(side = LEFT, expand = True, fill = "both",)
btnminus = Button(
btnrow2,
text = "-",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_minus_clicked,
)
btnminus.pack(side = LEFT, expand = True, fill = "both",)
btn7 = Button(
btnrow3,
text = "7",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_7_isclicked,
)
btn7.pack(side = LEFT, expand = True, fill = "both",)
btn8 = Button(
btnrow3,
text = "8",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_8_isclicked,
)
btn8.pack(side = LEFT, expand = True, fill = "both",)
btn9 = Button(
btnrow3,
text = "9",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_9_isclicked,
)
btn9.pack(side = LEFT, expand = True, fill = "both",)
btnmult = Button(
btnrow3,
text = "*",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = btn_mult_clicked,
)
btnmult.pack(side = LEFT, expand = True, fill = "both",)
btndot = Button(
btnrow4,
text = ".",
font = ("Verdana", 22),
bg="#b9ebfa",
relief = GROOVE,
border = 0,
command = b
xiaoshun007~
- 粉丝: 4105
- 资源: 3118
最新资源
- 三电平逆变器 仿真 SVPWM调制 中点电位平衡控制 可选svpwm or spwm T型 I型NPC和ANPC(拓扑都有可以选) 包含三相逆变器参数设计,SVPWM,直流均压控制,双闭环控制说明文档
- 《离散数学(第二版)》知识点总结
- 1234578909u有天翻地覆
- comsol激光打孔(不通)水平集两相流仿真模型,涉及温度场流场水平集, 模型为复现模型,仅供学习,可自己更材料功率等参数 爽快确认模型无误并收送变形几何三维打孔模型或水平集抛光模型
- 主控芯片市场调研报告:2024年全球主控芯片市场销售额为24.23亿美元
- 三相不平衡电压下T型NPC三电平并网逆变器并网控制 1.采用正负序分离锁相环以及正序PI控制,负序PI控制 2.采用中点电位平衡控制-零序电压注入法 3.采用SVPWM羊角波调制方式 4.提供参考文献
- 轨道交通信号与控制专业综合实验指导手册-FSK信号处理、应答器报文编制与CRC校验
- telnet 离线安装文件,适用于Centos8 和redhat
- 固态电池市场增长潜力:2024年全球固态电池市场销售额为1.08亿美元
- helpful-base-1.wav
- 含压缩空气储能的冷热电联供微网运行优化策略matlab
- 毕设&课程作业_基于C#的访问物联网电缆测量系统的API.zip
- 毕设&课程作业_基于C#的教师工作量管理系统 .zip
- 连锁书店市场发展现状:2023年线上书店市场规模超过1.05亿元
- 毕设&课程作业_基于C#的社团管理系统 .zip
- 毕设&课程作业_基于C#的内容管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页