RecursionError while trying to change background on multiple windows in python tkinter
<p>Last night I started a mini project where I wanted to make a game using <code>tkinter</code> (as opposed to <code>pygame</code> mainly because I don't know how to make multiple windows in <code>pygame</code>). </p>

<p>I want the user to guess the RGB values and compute their accuracy. Yet, whenever I run my code I get a <code>RecursionError</code> during the <code>startgame</code> function and none of the colors change. I'm confused as to why.</p>

<pre><code>from tkinter import *
import random

class multiWindow(Tk):
def __init__(self):

    # ******* CREATE WINDOWS *******

    window1 = Tk()
    window2 = Tk()
    window3 = Tk()

    # ******* WINDOW DIMENSIONS *******

    windowH = 100
    windowW = 250

    # ******* SCREEN RES *******

    screenW = 1366-windowW
    screenH = 768-windowH

    # ******* COORDINATES OF WINDOWS *******
    window1.geometry('%dx%d+%d+%d' % (windowW,windowH,screenW/6,screenH/3))
    window2.geometry('%dx%d+%d+%d' % (windowW,windowH,screenW/2,screenH/3))
    window3.geometry('%dx%d+%d+%d' % (windowW,windowH,screenW/(6/5),screenH/3))

    # ******* WINDOW TITLES *******
    window1.title("Color1")
    window2.title("Color2")
    window3.title("Color3")

    # ******** BUTTON START *******
    buttonStart = Button(window1,text="Start Game", command=lambda: self.startGame())
    buttonStart.pack()


    # ******* OPEN WINDOWS ******* 
    window1.mainloop()
    window2.mainloop()
    window3.mainloop()




# ******** PRODUCE RANDOM COLOR ********
def randomRGB(self):
    return random.randint(0,255)


def guessRed(self,window):
    while True:
        try:
            print("I want you to guess the RGB values of the colors in the windows above.")
            print("Guess the red value of the window displaying ",window)
            guess = int(input())

            if guess &lt; 0 or guess &gt; 255:
                raise
            else:
                return guess
                break
        except:
            print("Error")

def startGame(self):
    # ******** DETERMINE COLOR VALUES *******
    colorVal = [0,0,0,0,0,0,0,0,0]

    for x in range(0,len(colorVal)):
        colorVal[x] = self.randomRGB()

    # ******* GIVE WINDOWS COLOR *******
    self.window1.configure(background='#%02x%02x%02x'%(colorVal[0],colorVal[1],colorVal[2],))
    self.window2.configure(background='#%02x%02x%02x'%(colorVal[3],colorVal[4],colorVal[5],))
    self.window3.configure(background='#%02x%02x%02x'%(colorVal[6],colorVal[7],colorVal[8],))

multiWindow = multiWindow()
print("This comes after multiwindow class")        
</code></pre>

<p>I'm not very well adversed in <code>tkinter</code>. Just started reading about it 2 days ago, but I feel this problem has less to do with my grasp of <code>tkinter</code> than my grasp of python. </p>

<p>Any help is greatly appreciated</p>

<p>Your program must have exactly one instance of <code>Tk</code>, and you must call <code>mainloop</code> exactly once. If you need additional windows, create instances of <code>Toplevel</code>. Nothing will work the way you expect if you have more than one instance of <code>Tk</code>. </p>

<p>You also need to remove your infinite loop in <code>guessRed</code> as well as the call to <code>input</code>. A GUI shouldn't be getting input from the console. </p>

<hr>

<p>Unrelated to any other problems, you don't need to use <code>lambda</code> in the following:</p>

<pre><code>Button(window1,text="Start Game", command=lambda: self.startGame())
</code></pre>

<p>In this case the <code>lambda</code> serves no purpose other than to make the code slightly more complex. Instead, just pass a reference to the function:</p>

<pre><code>Button(window1,text="Start Game", command=self.startGame)
</code></pre>

python tkinter python-3.5