生成一个python语言的计算器代码,要求包含有界面
时间: 2023-03-13 22:17:52 浏览: 93
答案:下面是一个用Python语言编写的带有界面的计算器的代码:from tkinter import *
# Create the window
window = Tk()
window.title("Calculator")
window.geometry("400x400")# Create the text field
text_field = Entry(window, width=20, bg="white")
text_field.grid(row=0, column=0, columnspan=3, padx=10, pady=10)# Create the buttons
button1 = Button(window, text="1", width=5)
button1.grid(row=1, column=0, padx=10, pady=10)button2 = Button(window, text="2", width=5)
button2.grid(row=1, column=1, padx=10, pady=10)button3 = Button(window, text="3", width=5)
button3.grid(row=1, column=2, padx=10, pady=10)button4 = Button(window, text="4", width=5)
button4.grid(row=2, column=0, padx=10, pady=10)button5 = Button(window, text="5", width=5)
button5.grid(row=2, column=1, padx=10, pady=10)button6 = Button(window, text="6", width=5)
button6.grid(row=2, column=2, padx=10, pady=10)button7 = Button(window, text="7", width=5)
button7.grid(row=3, column=0, padx=10, pady=10)button8 = Button(window, text="8", width=5)
button8.grid(row=3, column=1, padx=10, pady=10)button9 = Button(window, text="9", width=5)
button9.grid(row=3, column=2, padx=10, pady=10)button0 = Button(window, text="0", width=5)
button0.grid(row=4, column=0, padx=10, pady=10)button_add = Button(window, text="+", width=5)
button_add.grid(row=1, column=3, padx=10, pady=10)button_subtract = Button(window, text="-", width=5)
button_subtract.grid(row=2, column=3, padx=10, pady=10)button_multiply = Button(window, text="*", width=5)
button_multiply.grid(row=3, column=3, padx=10, pady=10)button_divide = Button(window, text="/", width=5)
button_divide.grid(row=4, column=3, padx=10, pady=10)button_equal = Button(window, text="=", width=5)
button_equal.grid(row=4, column=2, padx=10, pady=10)window.mainloop()
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)