# 【安安教具】-【数学】-【一阶线性齐次方程】模拟器 教你如何用python制作一阶线性齐次方程模拟器 python项目小发明

这样一个式子，其通解为：

所以这个模型的难点是求积分。。。

``````x = symbols("x")
f=eval(list_get)
A = integrate(f, x)``````

``````class basedesk():#底板
def __init__(self, master):
self.master = master
self.master.title("一阶微分方程模拟器")
self.master.configure(bg='#B1FFF9')
self.master.geometry("1000x600")
mainwindow(self.master)
class mainwindow():#主界面
def __init__(self, master):
self.master = master
self.window = tk.Frame(self.master, bg='#e5ffe5')
self.window.place(x=0,y=0,width=1000,height=600)
self.window.showname_label=tk.Label(self.window,text="一阶微分方程模拟器",fg='#26734d', bg='#ffe5ff',font=("Helvetic",60,"bold"),relief=RAISED).place(x=0, y=10,width=1000, height=150)
self.window.enter_btn=tk.Button(self.window,text="开始",bg='#ffffe5',fg='#333399',font=("Helvetic", 60, "bold"),command=self.changetofunction).place(x=360, y=300,width=250, height=150)
def changetofunction(self,):
self.window.destroy()
functionwindow(self.master)
class functionwindow():
def __init__(self, master):
self.master = master
self.window = tk.Frame(self.master, bg='#e5f9ff')
self.window.place(x=0, y=0, width=1000, height=600)
self.window.left_label = tk.Label(self.window, text="y'+", font=("Helvetic", 20, "bold"), bg='#e5f9ff').place(x=10, y=100)
self.window.right_label = tk.Label(self.window, text="y=0", font=("Helvetic", 20, "bold"), bg='#e5f9ff').place(x=900, y=100)
self.window.entry1=tk.Entry(self.window, font=("Helvetica", 20))
self.window.entry1.place(x=90, y=100, width=800, height=40)
self.window.enter_btn=tk.Button(self.window,text="计算一阶线性齐次方程的通解",bg='#ffffe5',fg='#333399',font=("Helvetic", 30, "bold"),command=self.calculate).place(x=200, y=300,width=570, height=100)``````

``````    def calculate(self):
list_get=self.window.entry1.get()
if list_get=='':
messagebox.showerror('错误','输入的一元方程不能为空')
return

try:
x = symbols("x")
f=eval(list_get)
A = integrate(f, x)
except:
messagebox.showerror("错误",'输入格式有误')``````

``````#一阶微分方程模拟器
from tkinter import *
from tkinter import messagebox
import tkinter as tk
from sympy import *
class basedesk():#底板
def __init__(self, master):
self.master = master
self.master.title("一阶微分方程模拟器")
self.master.configure(bg='#B1FFF9')
self.master.geometry("1000x600")
mainwindow(self.master)
class mainwindow():#主界面
def __init__(self, master):
self.master = master
self.window = tk.Frame(self.master, bg='#e5ffe5')
self.window.place(x=0,y=0,width=1000,height=600)
self.window.showname_label=tk.Label(self.window,text="一阶微分方程模拟器",fg='#26734d', bg='#ffe5ff',font=("Helvetic",60,"bold"),relief=RAISED).place(x=0, y=10,width=1000, height=150)
self.window.enter_btn=tk.Button(self.window,text="开始",bg='#ffffe5',fg='#333399',font=("Helvetic", 60, "bold"),command=self.changetofunction).place(x=360, y=300,width=250, height=150)
def changetofunction(self,):
self.window.destroy()
functionwindow(self.master)
class functionwindow():
def __init__(self, master):
self.master = master
self.window = tk.Frame(self.master, bg='#e5f9ff')
self.window.place(x=0, y=0, width=1000, height=600)
self.window.left_label = tk.Label(self.window, text="y'+", font=("Helvetic", 20, "bold"), bg='#e5f9ff').place(x=10, y=100)
self.window.right_label = tk.Label(self.window, text="y=0", font=("Helvetic", 20, "bold"), bg='#e5f9ff').place(x=900, y=100)
self.window.entry1=tk.Entry(self.window, font=("Helvetica", 20))
self.window.entry1.place(x=90, y=100, width=800, height=40)
self.window.enter_btn=tk.Button(self.window,text="计算一阶线性齐次方程的通解",bg='#ffffe5',fg='#333399',font=("Helvetic", 30, "bold"),command=self.calculate).place(x=200, y=300,width=570, height=100)
def calculate(self):
list_get=self.window.entry1.get()
if list_get=='':
messagebox.showerror('错误','输入的一元方程不能为空')
return

try:
x = symbols("x")
f=eval(list_get)
A = integrate(f, x)
except:
messagebox.showerror("错误",'输入格式有误')

if __name__ == '__main__':#主函数
root = tk.Tk()
root.resizable(False, False)
basedesk(root)
root.mainloop()``````

原文作者：安城安教具
原文地址: https://blog.csdn.net/anananajiushiwo/article/details/122758086
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。