Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class Tkinter Python-使用多个变量运行类循环_Class_Variables_For Loop_Tkinter - Fatal编程技术网

Class Tkinter Python-使用多个变量运行类循环

Class Tkinter Python-使用多个变量运行类循环,class,variables,for-loop,tkinter,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) # no

我需要根据我给他的输入(本例中有几个值),对一个算法(作为类编写)进行一定次数的重新迭代

例如:

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循环,但不能用多个变量

我看不出有什么实际问题。如果我添加了缺少的导入,我相信代码会正常运行。看,我写的这段代码适用于两个变量a和b。我需要做的是首先确定我需要多少对,例如3对(a1,b1)(a2,b2)(a3,b3),然后让代码显示我需要的输入窗口小部件的数量(本例中为6个),然后用每对值运行算法3次。我不想重复三次(就像我在这里写的代码一样),但每两个值只重复一次!希望我是清楚的