|
发表于 2021-12-10 18:33:15
|
显示全部楼层
我帮你重新编写了:(多了个按钮功能)- from tkinter import *
- root = Tk()
- costLabel = Label(root, text = "成本").grid(row = 0, column = 0)
- qtyLabel = Label(root, text = "数量").grid(row = 0, column = 1)
- totalLabel = Label(root, text = "总价").grid(row = 0, column = 2)
- costBox = Entry(root, width = 30, bg = '#00ffff', borderwidth = 5)
- costBox.grid(row = 1, column = 0, padx = 5, pady = 5)
- qtyBox = Entry(root, width = 30, bg = '#00ffff', borderwidth = 5)
- qtyBox.grid(row = 1, column = 1, padx = 5, pady = 5)
- totalBox = Entry(root, width = 30, bg = '#00ffff', borderwidth = 5)
- totalBox.grid(row = 1, column = 2, padx = 5, pady = 5)
- def calculate():
- x = int(costBox.get())
- y = int(qtyBox.get())
- totalBox.delete(0, END)
- totalBox.insert(0, f"{x*y: .2f} 元")
- buttonEnter = Button(root, text = "确定", padx = 40, pady = 20, command = lambda: calculate())
- buttonEnter.grid(row = 2, column = 2, padx = 5, pady = 5)
- root.mainloop()
复制代码 |
|