我尝试使用PuLP库创建程序,当您点击按钮时,它解决了线性问题并输出值。所以这是我在尝试优化输入值时得到的结果:
TypeError: problem() takes 0 positional arguments but 7 were given.
此时我不确定我是否理解这个TypeError试图告诉我的内容。
from tkinter import*
from pulp import*
def problem():
prob=LpProblem("problem", LpMaximize)
x1=LpVariable("x1", lowBound=0)
x2=LpVariable("x2", lowBound=0)
x3=LpVariable("x3", lowBound=0)
prob+= a*x1 +b*x2 +c*x3,
prob+= d*x1 +e*x2 + f*x3 <= g,
prob.solve ()
print("status:", LpStatus[prob.status])
for v in prob.variables():
print (v.name, "=", v.varValue)
print("objective=%s$" % value(prob.objective))
root =Tk()
root.title("System")
root.geometry("1300x500+0+0")
a=Entry(Top, font=("arial", 10, "bold"), bd=8)
a.grid(row=1, column=1)
b=Entry(Top, font=("arial", 10, "bold"), bd=8)
b.grid(row=1, column=2)
c=Entry(Top, font=("arial", 10, "bold"), bd=8)
c.grid(row=1, column=3)
d=Entry(Top, font=("arial", 10, "bold"), bd=8)
d.grid(row=2, column=1)
e=Entry(Top, font=("arial", 10, "bold"), bd=8)
e.grid(row=2, column=2)
f=Entry(Top, font=("arial", 10, "bold"), bd=8)
f.grid(row=2, column=3)
g=Entry(Top, font=("arial", 10, "bold"), bd=8)
g.grid(row=3, column=1)
def inserter (value):
w.delete("0.0", "end")
w.insert("0.0", value)
def handler():
try:
g_val = float(g.get())
a_val = float(a.get())
b_val = float(b.get())
c_val = float(c.get())
d_val = float(d.get())
e_val = float(e.get())
f_val = float(f.get())
inserter(problem(a_val,b_val,c_val,d_val,e_val,f_val, g_val))
except ValueError:
inserter("Enter more values")
w=Text(Top, font=("arial", 10, "bold"), bd=6)
w.grid(row=4, column=1)
info6=Button(Top, font=("arial", 10,"bold"), text="Optimize", bd=8, command=handler)
info6.grid(row=4, column=0)
root.mainloop()
答案 0 :(得分:0)
你有一个problem()
方法,它接受0个参数,但你试图通过一些参数调用它。您应该更改方法的定义以获取这些参数,在这种情况下,更改方法主体以处理这些参数似乎是合乎逻辑的,或者在不传递参数的情况下调用problem()
。