Так что проблема в том, что когда я нажимаю радиокнопки, ничего не меняется - их команда не обрабатывается. Я всегда получаю результат так, как если бы были нажаты radio2
и radio4
. Пожалуйста помоги!Radiobutton, команда не работает (python)
# -*- coding: cp1250 -*-
import numpy as np
from scipy.optimize import minimize
import Tkinter
class numerika(Tkinter.Tk):
def __init__(self, parent):
Tkinter.Tk.__init__(self, parent)
self.parent = parent
self.title('Optimizacija funkcije')
self. geometry('500x300')
self.uvjeti = ({'type': 'ineq', 'fun': lambda x: np.array([-x[0]-2*x[1]+4.0])},
{'type': 'ineq', 'fun': lambda x: np.array([-4*x[0] - 2*x[1] +12.0])},
{'type': 'ineq', 'fun': lambda x: np.array([x[0]-x[1]+1.0])},
{'type': 'ineq', 'fun': lambda x: np.array([x[0]])},
{'type': 'ineq', 'fun': lambda x: np.array([x[1]])})
self.initialize()
def initialize(self):
label1 = Tkinter.Label(self, text = u'Ovaj kod može izračunavati globalne ekstreme ravnine:').place(x = 10, y = 10)
label2 = Tkinter.Label(self, text = u'z = x1 +x2,').place(x = 70, y = 30)
label3 = Tkinter.Label(self, text = u'za zadane uvjete:').place(x = 70, y = 50)
label4 = Tkinter.Label(self, text = u'x1+2*x2 <= 4, 4*x1+2*x2 <= 12, -x1+x2 <= 1, x1 >= 0, x2 >= 0.').place(x = 70, y = 70)
label5 = Tkinter.Label(self, text = u'Odaberi tip ekstrema:').place(x = 10, y = 110)
label6 = Tkinter.Label(self, text = u'Odaberi metodu solvera:').place(x = 200, y = 110)
redio1 = Tkinter.Radiobutton(self, text = 'Maksimum', value = 1, variable = 1, command = self.a(-1)).place(x = 30, y = 140)
radio2 = Tkinter.Radiobutton(self, text = 'Minimum', value = 2, variable = 1, command = self.a(1)).place(x = 30, y = 170)
radio3 = Tkinter.Radiobutton(self, text = 'COBYLA', value = 3, variable = 2, command = self.b('COBYLA')).place(x = 220, y = 140)
radio4 = Tkinter.Radiobutton(self, text = 'SLSQP', value = 4, variable = 2, command = self.b('SLSQP')).place(x = 220, y = 170)
dugmic1 = Tkinter.Button(self, text = u'Izračunaj!', height = 3, bd = 3, command = self.racunaj).place(x = 390, y = 140)
def racunaj(self):
rj = minimize(self.f, [1.0, 1.0], method = self.m, constraints = self.uvjeti)
self.rj = rj
def f(self,x):
x1 = x[0]
x2 = x[1]
return self.k*(x1+x2)
def a(self, k):
self.k = k
def b(self, m):
self.m = m
app=numerika(None)
app.mainloop()
print app.rj