aiaiask.com©

开花即结果 提问即答案

帮我写一个python计算器,要求是科学计算器,且GUI界面美观大气上档次,谢谢
原始问题:

帮我写一个python计算器,要求是科学计算器,且GUI界面美观大气上档次,谢谢

from tkinter import *  # 导入tkinter模块
import math  # 导入math模块
 
# 科学计算器的GUI界面设计
root = Tk()  # 创建根窗口对象,用于显示整个GUI界面的容器,后续所有的都要添加到这个root中去。
root.title('科学计算器')  # 设置标题文本内容为“科学计算器”。
root.geometry("400x400")  # 调整整体GUI界面大小,宽度*高度。

 
# 显示文本框:由Label来显式文本内容到GUI界面上。   entry_text表明是一个文本框(Entry)对象。   width=50表明该文本框的宽度是50个字体大小。    bg='white'表明背景是white也就是说该文本框背景是浅色的(light color)    fg='black'表明前端(foreground)是black也就是说前端字体颜色是黑色的(dark color)    font=('Arial', 12) 这里font表明使用Arial这个字体,12这个大小来作为文本内容在GUI界面上所使用的样式.     justify=RIGHT,表明他会以右对其方式来对待我们地entry_text所作出地修正.   state='readonly'表明entry_text不可以直接通过我们地keyboard来录入或者修正内容,而只能通过代码来修正内容.     textvariable=result 把result变量传递到entry_text中去,并将result中得内容作为entry_text所要show出来得内容.    entry_text = Entry(root, width=50, bg='white', fg='black', font=('Arial', 12), justify=RIGHT, state='readonly', textvariable=result).grid(row = 0 ,columnspan = 4 )

                                                                                         # row:0; columnspan:4; grid()函数将上一歩所创建得Entry对象加关到我们地root GUI界面上去; row:0; columnspan:4; 连合使电子录入/修正区占4格row0.

 result = StringVar()   # StringVar()函數來創立一個StringVar物件;StringVar物件代衳一舊str物件;StringVar物件支裂TKinter GUI 畫布之間傳遞/傳回str物件之功能  達到互動性之相關功能..

                                                     # 创立9*5 button Grid ; i in range (1 , 10): i in [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 9] ; j in range (1 ,6): j in [1,2,3,4 5] ; sticky : N+E+W+S : North + East + West + South : 各button都会四周伸張 .

 for i in range (1 , 10):            # for loop to create each button from 1 to 9 and '.' and 'AC' .      command : lambda x = i: calc(x) : calc function take x as a parameter .      if i == 0 : text 'AC' else text str(i).       if i < 4: row number is 1 . else if 3<i<7 : row number is 2 . else if 6<i<10 : row number is 3 .       sticky keyword argument to make the button expand around all side by using N+E+W+S direction constant value.        Button ( root , text = 'AC'if i == 0 else str (i), width = 5 , height = 3command = lambda x ==> calc (x)).grid (row - 1if i < 4 else 2if 3<i<7else3column - 1if 0 <i %3==0else 2if 1 <=i %3==0else 3stickyN + E + W + S )
帮我写一个python计算器,要求是科学计算器,且GUI界面美观大气上档次,谢谢
https://www.aiaiask.com/ask/6957.html
AI / 模型iFLYTEK
时间 / DATEApril 6, 2023, 7:54 PM
语言zh-CN
IP / 区域陕西 西安