用户:
开源盛世查看:5 回复:6 评论:5 创建时间:2020-05-09T17:31:09
0.作品展示
1.源代码:
from tkinter import *
from tkinter.messagebox import *
def getanswer():
try:
a=int(e1.get())
b=int(e2.get())
if a==0:raise ZeroDivisionError
except ZeroDivisionError:
showerror('错误','一次项系数不能为零')
except ValueError:
showerror('错误','输入错误')
else:
showinfo('成功','解为{:.6f}'.format(-b/a))
root=Tk()
root.title("解一元一次方程")
root.geometry("260x60")
root.resizable(False,False)
e1=Entry(root,width=4)
e1.place(x=60,y=20)
e2=Entry(root,width=4)
e2.place(x=113,y=20)
Label(root,text='x+').place(x=92,y=20)
Label(root,text='=0').place(x=145,y=20)
Button(root,text='求解',bg='orange',fg='white',command=getanswer).place(x=220,y=20)
mainloop()
2.原理
原理自然就很简单了,形式如 ax+b=0 的一元一次方程的解是 x=-b/a。但是这也涉及到一些图形界面的知识,例如主窗口的创建及使用、文本框、按钮、标签的添加及使用,消息框的使用等。
以后还将陆续推出新的版本哦!