Tkinter-Python-运行具有多个变量的类循环

时间:2016-03-06 23:06:13

标签: class variables for-loop tkinter

我需要重新迭代一个算法(写成一个类)一定次数,这取决于我给他的输入(在这种情况下是几个值)。

例如:

class Main:

    def __init__(self, master):

        #here I decide the numbers of iterations (and number of couples values)
        self.n=tk.Entrywidget( master, textvariable=StringVar)
        # now I must create something for the n couple of values,
        # thinking about n couples of entry, don't know how to bind
        # the number of entry widgets to the value of n
        # so I'll create just one
        self.aentry=tk.Entrywidget( master, textvariable= StringVar)
        self.bentry= tk.Entrywidget (master, textvariable= StringVar)
        runbutton= tk.Button( master, command= self.run)

    def run(self):

        self.class1= Class1(self)  

class Class1:  #here I'll write the algoritm

    def __init__(self,master):

        self.a= master.aentry.get()
        self.b= master.bentry.get()
        self.c= self.a +  self.b

所以我想编写n对值,例如:

n = 2,其中a1 = 1,b1 = 3,a2 = 3,b2 = 5,其中4和8是Class1算法的结果! 我正在考虑一个for循环,但不能用多个变量做到这一点!

0 个答案:

没有答案