ChatGTP写的Windows计算器,挺靠谱低端程序员估计很快要失业


用能用 python 语言帮我写一个程序吗?

当然可以,我可以使用 Python 为您编写程序。请告诉我您需要的程序的具体功能和要求,我将尽力为您提供帮助。

用 Python 编写一个程序实现 Windows 程序自带的计算器的功能

好的,以下是一个简单的 Python 程序,可以实现 Windows 程序自带的计算器的基本功能:

# 导入 tkinter 模块
from tkinter import *

# 创建一个 Tkinter 窗口
window = Tk()
window.title("计算器")

# 定义全局变量
expression = ""

# 定义按钮点击事件
def button_click(num):
    global expression
    expression = expression + str(num)
    equation.set(expression)

def button_clear():
    global expression
    expression = ""
    equation.set("0")

def button_equal():
    try:
        global expression
        total = str(eval(expression))
        equation.set(total)
        expression = ""
    except:
        equation.set("错误")
        expression = ""

# 定义显示结果的变量
equation = StringVar()
equation.set("0")

# 创建计算器显示屏
display = Entry(window, textvariable=equation, font=("Arial", 20), justify="right")
display.grid(columnspan=4, ipadx=10, ipady=10)

# 创建数字按钮
button_1 = Button(window, text="1", font=("Arial", 16), command=lambda: button_click(1))
button_1.grid(row=1, column=0)

button_2 = Button(window, text="2", font=("Arial", 16), command=lambda: button_click(2))
button_2.grid(row=1, column=1)

button_3 = Button(window, text="3", font=("Arial", 16), command=lambda: button_click(3))
button_3.grid(row=1, column=2)

button_4 = Button(window, text="4", font=("Arial", 16), command=lambda: button_click(4))
button_4.grid(row=2, column=0)

button_5 = Button(window, text="5", font=("Arial", 16), command=lambda: button_click(5))
button_5.grid(row=2, column=1)

button_6 = Button(window, text="6", font=("Arial", 16), command=lambda: button_click(6))
button_6.grid(row=2, column=2)

button_7 = Button(window, text="7", font=("Arial", 16), command=lambda: button_click(7))
button_7.grid(row=3, column=0)

button_8 = Button(window, text="8", font=("Arial", 16), command=lambda: button_click(8))
button_8.grid(row=3, column=1)

button_9 = Button(window, text="9", font=("Arial", 16), command=lambda: button_click(9))
button_9.grid(row=3, column=2)

button_0 = Button(window, text="0", font=("Arial", 16), command=lambda: button_click(0))
button_0.grid(row=4, column=1)

# 创建操作符按钮
button_plus = Button(window, text="+", font=("Arial", 16), command=lambda: button_click("+"))
button_plus.grid(row=1, column=3)

button_minus = Button(window, text="-", font=("Arial", 16), command=lambda: button_click("-"))
button_minus.grid(row=2, column=3)

button_multiply = Button(window, text="*", font=("Arial", 16), command=lambda: button_click("*"))
button_multiply.grid(row=3, column=3)

button_pide = Button(window, text="/", font=("Arial", 16), command=lambda: button_click("/"))
button_pide.grid(row=4, column=3)

button_clear = Button(window, text="C", font=("Arial", 16), command=button_clear)
button_clear.grid(row=4, column=0)

button_equal = Button(window, text="=", font=("Arial", 16), command=button_equal)
button_equal.grid(row=4, column=2)

# 运行窗口
window.mainloop()

这个程序使用 tkinter 模块创建了一个简单的窗口,包括数字按钮、操作符按钮和一个显示屏。用户可以通过单击按钮来输入数字和操作符,并在显示屏上查看计算结果。

Chat GTP帮我写的Windows计算器功能,挺靠谱,低端程序员估计很快要失业。

展开阅读全文

页面更新:2024-03-30

标签:计算器   低端   程序员   显示屏   模块   按钮   定义   窗口   操作   功能   数字   程序

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top