With my program, I have been trying to simulate the game of Roulette (at a casino) with a GUI, but I have a problem that I can't seem to figure out.

For some reason, any kind of accumulator for "current funds" I place in the program doesn't seem to work properly. I tried turning the "current funds" itself into a class, so that it could keep track of itself whenever money was gained or lost. However, it is still not working properly. It seems as if the while loop is not working properly, and it is an infinite loop (so be careful if you try to run my code).

whithout the while loop in place, the program doesn't keep updating the current funds for each time it is clicked, it only records the gain/loss once, and then seems to reset itself back to 300.

I'm baffled by this problem, and I can't seem to think of any solution. I tried to use comments to help explain what is doing what, so I hope that helps.

If you try to run any test cases, I suggest that you only use the "00" rectangle for your tests, as I haven't fully updated the other rectangles yet. Also, the way the program should work, is by first placing the amount you would like to bet inside the entry box, and then clicking the rectangle you would like to bet on. Once you click, it is supposed to simulate the 'spinning' of the roulette.

#Roulette.py
# The purpose of this program is to simulate a game of 'Roulette'.
# CS110 final project
# By Matthew Pennisi

from random import randrange
from Tkinter import *

class Roulette:
    def __init__(self, slots):
        self.slots = slots
        self.value = 1

    def spin(self):
        self.value = randrange(1, self.slots+1)

    def getValue(self):
        return self.value

class CurrentFunds:
    def __init__(self):
        self.value = 300

    def getValue(self):
        return self.value

    def increase(self, add):
        self.value = self.value + add
        
    def decrease(self, minus):
        self.value = self.value - minus
        
	
def cashOut(bet, spin, x, y):

    #Callback for the Error box.
    def errorWindow():
        root = Tk()
        root.title('Error')
        outsideTable(root)
        root.mainloop()

    currentFunds = CurrentFunds()
    
    #These coordinates are outside the table on the canvas.
    if (x<11 or x>389 or y<15 or y>215) or \
       (x>11 and x<38 and y>165 and y<215) or \
       (x>362 and x<389 and y>165 and y<215):
         errorWindow() #Error box appears.

    #These coordinates find which space was bet on.
    elif x>11 and x<389 and y>15 and y<215:
        #The 00 Rectangle.
        if x>11 and x<38 and y>15 and y<90:
            if spin == 1:
                increase = (38 * bet) - bet
                currentFunds.increase(increase)
                #print statement is to see if the accumulator works, which it currently isn't.
                #It only increases/decreases once, instead of for each bet.
                #These will be taken out for the final product.
                print currentFunds.getValue()
            else:
                decrease = bet
                currentFunds.decrease(decrease)
                #print statement is to see if the accumulator works, which it currently isn't.
                #It only increases/decreases once, instead of for each bet.
                #These will be taken out for the final product.
                print currentFunds.getValue()
        #The 0 Rectangle.
        elif x>11 and x<38 and y>90 and y<165:
            if spin == 2:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
                
        #Rectangles 1 - 36.
        elif x>38 and x<65 and y>115 and y<165:
            if spin == 3:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>38 and x<65 and y>65 and y<115:
            if spin == 4:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>38 and x<65 and y>15 and y<65:
            if spin == 5:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>65 and x<92 and y>115 and y<165:
            if spin == 6:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>65 and x<92 and y>65 and y<115:
            if spin == 7:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>65 and x<92 and y>15 and y<65:
            if spin == 8:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>92 and x<119 and y>115 and y<165:
            if spin == 9:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>92 and x<119 and y>65 and y<115:
            if spin == 10:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>92 and x<119 and y>15 and y<65:
            if spin == 11:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>119 and x<146 and y>115 and y<165:
            if spin == 12:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>119 and x<146 and y>65 and y<115:
            if spin == 13:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>119 and x<146 and y>15 and y<65:
            if spin == 14:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>146 and x<173 and y>115 and y<165:
            if spin == 15:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>146 and x<173 and y>65 and y<115:
            if spin == 16:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>146 and x<173 and y>15 and y<65:
            if spin == 17:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>173 and x<200 and y>115 and y<165:
            if spin == 18:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>173 and x<200 and y>65 and y<115:
            if spin == 19:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>173 and x<200 and y>15 and y<65:
            if spin == 20:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>200 and x<227 and y>115 and y<165:
            if spin == 21:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>200 and x<227 and y>65 and y<115:
            if spin == 22:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>200 and x<227 and y>15 and y<65:
            if spin == 23:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>227 and x<254 and y>115 and y<165:
            if spin == 24:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>227 and x<254 and y>65 and y<115:
            if spin == 25:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>227 and x<254 and y>15 and y<65:
            if spin == 26:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>254 and x<281 and y>115 and y<165:
            if spin == 27:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>254 and x<281 and y>65 and y<115:
            if spin == 28:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>254 and x<281 and y>15 and y<65:
            if spin == 29:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>281 and x<308 and y>115 and y<165:
            if spin == 30:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>281 and x<308 and y>65 and y<115:
            if spin == 31:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>281 and x<308 and y>15 and y<65:
            if spin == 32:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>308 and x<335 and y>115 and y<165:
            if spin == 33:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>308 and x<335 and y>65 and y<115:
            if spin == 34:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>308 and x<335 and y>15 and y<65:
            if spin == 35:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>335 and x<362 and y>115 and y<165:
            if spin == 36:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>335 and x<362 and y>65 and y<115:
            if spin == 37:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>335 and x<362 and y>15 and y<65:
            if spin == 38:
                gainOrLoss =(38 * bet) - bet
            else:
                gainOrLoss = -(bet)
                
        #The three 2 to 1 Rectangles.
        elif x>362 and x<389 and y>115 and y<165:
            if spin == 3 or spin == 6 or spin == 9 or spin == 12 or spin == 15 or spin == 18 \
               or spin == 21 or spin == 24 or spin == 27 or spin == 30 or spin == 33 or spin == 36:
                gainOrLoss =(3 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>362 and x<389 and y>65 and y<115:
            if spin == 4 or spin == 7 or spin == 10 or spin == 13 or spin == 16 or spin == 19 \
               or spin == 22 or spin == 25 or spin == 28 or spin == 31 or spin == 34 or spin == 37:
                gainOrLoss =(3 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>362 and x<389 and y>15 and y<65:
            if spin == 5 or spin == 8 or spin == 11 or spin == 14 or spin == 17 or spin == 20 \
               or spin == 23 or spin == 26 or spin == 29 or spin == 32 or spin == 35 or spin == 38:
                 gainOrLoss =(3 * bet) - bet
            else:
                gainOrLoss = -(bet)
                
        #First 12, Second 12, Third 12 Rectangles.
        elif x>38 and x<146 and y>165 and y<190:
            if spin == 3 or spin == 4 or spin == 5 or spin == 6 or spin == 7 or spin == 8 \
               or spin == 9 or spin == 10 or spin == 11 or spin == 12 or spin == 13 or spin == 14:
                 gainOrLoss =(3 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>146 and x<254 and y>165 and y<190:
            if spin == 15 or spin == 16 or spin == 17 or spin == 18 or spin == 19 or spin == 20 \
               or spin == 21 or spin == 22 or spin == 23 or spin == 24 or spin == 25 or spin == 26:
                gainOrLoss =(3 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>254 and x<362 and y>165 and y<190:
            if spin == 27 or spin == 28 or spin == 29 or spin == 30 or spin == 31 or spin == 32 \
               or spin == 33 or spin == 34 or spin == 35 or spin == 36 or spin == 37 or spin == 38:
                gainOrLoss =(3 * bet) - bet
            else:
                gainOrLoss = -(bet)

        #Bottom row of rectangles (1-18, Even, Black, Red, Odd, 19-36).
        elif x>38 and x<92 and y>190 and y<215:
            if spin == 3 or spin == 4 or spin == 5 or spin == 6 or spin == 7 or spin == 8 or spin == 9 \
               or spin == 10 or spin == 11 or spin == 12 or spin == 13 or spin == 14 or spin == 15 \
                or spin == 16 or spin == 17 or spin == 18 or spin == 19 or spin == 20:
                gainOrLoss =(2 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>92 and x<146 and y>190 and y<215:
            if spin == 4 or spin == 6 or spin == 8 or spin == 10 or spin == 12 or spin == 14 or spin == 16 \
               or spin == 18 or spin == 20 or spin == 22 or spin == 24 or spin == 26 or spin == 28 \
                or spin == 30 or spin == 32 or spin == 34 or spin == 36 or spin == 38:
                gainOrLoss =(2 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>146 and x<200 and y>190 and y<215:
            if spin == 4 or spin == 6 or spin == 8 or spin == 10 or spin == 12 or spin == 13 or spin == 15 \
               or spin == 17 or spin == 19 or spin == 22 or spin == 24 or spin == 26 or spin == 28 \
               or spin == 30 or spin == 31 or spin == 33 or spin == 35 or spin == 37:
                gainOrLoss =(2 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>200 and x<254 and y>190 and y<215:
            if spin == 3 or spin == 5 or spin == 7 or spin == 9 or spin == 11 or spin == 14 or spin == 16 \
               or spin == 18 or spin == 20 or spin == 21 or spin == 23 or spin == 25 or spin == 27 \
               or spin == 29 or spin == 32 or spin == 34 or spin == 36 or spin == 38:
                gainOrLoss =(2 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>254 and x<308 and y>190 and y<215:
            if spin == 3 or spin == 5 or spin == 7 or spin == 9 or spin == 11 or spin == 13 or spin == 15 \
               or spin == 17 or spin == 19 or spin == 21 or spin == 23 or spin == 25 or spin == 27 \
               or spin == 29 or spin == 31 or spin == 33 or spin == 35 or spin == 37:
                gainOrLoss =(2 * bet) - bet
            else:
                gainOrLoss = -(bet)
        elif x>308 and x<362 and y>190 and y<215:
            if spin == 21 or spin == 22 or spin == 23 or spin == 24 or spin == 25 or spin == 26 or spin == 27 \
               or spin == 28 or spin == 29 or spin == 30 or spin == 31 or spin == 32 or spin == 33 or \
               spin == 34 or spin == 35 or spin == 36 or spin == 37 or spin == 38:
                gainOrLoss =(2 * bet) - bet
            else:
                gainOrLoss = -(bet)
        
    
def addWidgets(root):
    #Get the coordinates for the mouse click.
    def click(event):
        #This next line is just to make sure the coordinates are correct, it will be removed for the final product.
        print "Canvas clicked at", event.x, event.y 
        x, y = event.x, event.y
        spinRoulette(x, y) #Sends the mouse coordinates to spinRoulette.
                    
    def invalidWindow():
        root = Tk()
        root.title('Error')
        invalidBet(root)
        root.mainloop()

    def infoWindow():
        root = Tk()
        root.title('Information About The Game')
        addInfo(root)
        root.mainloop()
        
    def spinRoulette(x, y,):
        bet = float(betEntry.get())
        wheel = Roulette(38)
        wheel.spin()
        #result represents what the Roulette landed on.
        result = wheel.getValue()
        if bet <= 0:
            invalidWindow()
        elif bet > 0:
            if result == 1:
                resultLabel.config(text = 'The Roulette landed on 00')
            elif result == 2:
                resultLabel.config(text = 'The Roulette landed on 0')
            elif result == 3:
                resultLabel.config(text = 'The Roulette landed on 1')
            elif result == 4:
                resultLabel.config(text = 'The Roulette landed on 2')
            elif result == 5:
                resultLabel.config(text = 'The Roulette landed on 3')
            elif result == 6:
                resultLabel.config(text = 'The Roulette landed on 4')
            elif result == 7:
                resultLabel.config(text = 'The Roulette landed on 5')
            elif result == 8:
                resultLabel.config(text = 'The Roulette landed on 6')
            elif result == 9:
                resultLabel.config(text = 'The Roulette landed on 7')
            elif result == 10:
                resultLabel.config(text = 'The Roulette landed on 8')
            elif result == 11:
                resultLabel.config(text = 'The Roulette landed on 9')
            elif result == 12:
                resultLabel.config(text = 'The Roulette landed on 10')
            elif result == 13:
                resultLabel.config(text = 'The Roulette landed on 11')
            elif result == 14:
                resultLabel.config(text = 'The Roulette landed on 12')
            elif result == 15:
                resultLabel.config(text = 'The Roulette landed on 13')
            elif result == 16:
                resultLabel.config(text = 'The Roulette landed on 14')
            elif result == 17:
                resultLabel.config(text = 'The Roulette landed on 15')
            elif result == 18:
                resultLabel.config(text = 'The Roulette landed on 16')
            elif result == 19:
                resultLabel.config(text = 'The Roulette landed on 17')
            elif result == 20:
                resultLabel.config(text = 'The Roulette landed on 18')
            elif result == 21:
                resultLabel.config(text = 'The Roulette landed on 19')
            elif result == 22:
                resultLabel.config(text = 'The Roulette landed on 20')
            elif result == 23:
                resultLabel.config(text = 'The Roulette landed on 21')
            elif result == 24:
                resultLabel.config(text = 'The Roulette landed on 22')
            elif result == 25:
                resultLabel.config(text = 'The Roulette landed on 23')
            elif result == 26:
                resultLabel.config(text = 'The Roulette landed on 24')
            elif result == 27:
                resultLabel.config(text = 'The Roulette landed on 25')
            elif result == 28:
                resultLabel.config(text = 'The Roulette landed on 26')
            elif result == 29:
                resultLabel.config(text = 'The Roulette landed on 27')
            elif result == 30:
                resultLabel.config(text = 'The Roulette landed on 28')
            elif result == 31:
                resultLabel.config(text = 'The Roulette landed on 29')
            elif result == 32:
                resultLabel.config(text = 'The Roulette landed on 30')
            elif result == 33:
                resultLabel.config(text = 'The Roulette landed on 31')
            elif result == 34:
                resultLabel.config(text = 'The Roulette landed on 32')
            elif result == 35:
                resultLabel.config(text = 'The Roulette landed on 33')
            elif result == 36:
                resultLabel.config(text = 'The Roulette landed on 34')
            elif result == 37:
                resultLabel.config(text = 'The Roulette landed on 35')
            elif result == 38:
                resultLabel.config(text = 'The Roulette landed on 36')
            cashOut(bet, result, x, y)
                                     
    #Input information Widgets.
    bettingFrame = Frame(root)
    bettingFrame.pack()
    
    betLabel = Label(bettingFrame, text = 'Please enter a bet amount', \
                     fg = 'black')
    betLabel.pack()

    currentFundsLabel = Label(bettingFrame, text = 'You currently have $300.00')
    currentFundsLabel.pack()

    resultLabel = Label(bettingFrame, text = '')
    resultLabel.pack()

    dollarSignLabel = Label(bettingFrame, text = '$')
    dollarSignLabel.pack(side=LEFT)
    
    betEntry = Entry(bettingFrame, width = 10)
    betEntry.insert(0, 0)
    betEntry.pack(side=LEFT)

    

    #Create the canvas.
    rouletteTable = Canvas(root, width=400, height=230, bg = 'dark green')
    rouletteTable.pack(fill=BOTH)
    
    #Create optimal colors for red and blue.
    blueColor = "#%02X%02X%02X" % (0, 72, 76)
    redColor = "#%02X%02X%02X" % (222, 4, 4)

    #Coordinates for the Roulette Table.
    #These are all assigned variables so that is it easier to decipher which
    #rectangle on the Roulette table is being represented.    
    _00 = rouletteTable.create_rectangle(11,15,38,90, fill=blueColor, outline='white', width=3)
    _0 = rouletteTable.create_rectangle(11,90,38,165, fill=blueColor, outline='white', width=3)
    
    _1 = rouletteTable.create_rectangle(38,115,65,165, fill=redColor, outline='white', width=3)
    _2 = rouletteTable.create_rectangle(38,65,65,115, fill='black', outline='white', width=3)
    _3 = rouletteTable.create_rectangle(38,15,65,65, fill=redColor, outline='white', width=3)
    
    _4 = rouletteTable.create_rectangle(65,115,92,165, fill='black', outline='white', width=3)
    _5 = rouletteTable.create_rectangle(65,65,92,115, fill=redColor, outline='white', width=3)
    _6 = rouletteTable.create_rectangle(65,15,92,65, fill='black', outline='white', width=3)

    _7 = rouletteTable.create_rectangle(92,115,119,165, fill=redColor, outline='white', width=3)
    _8 = rouletteTable.create_rectangle(92,65,119,115, fill='black', outline='white', width=3)
    _9 = rouletteTable.create_rectangle(92,15,119,65, fill=redColor, outline='white', width=3)
    
    _10 = rouletteTable.create_rectangle(119,115,146,165, fill='black', outline='white', width=3)
    _11 = rouletteTable.create_rectangle(119,65,146,115, fill='black', outline='white', width=3)
    _12 = rouletteTable.create_rectangle(119,15,146,65, fill=redColor, outline='white', width=3)
    
    _13 = rouletteTable.create_rectangle(146,115,173,165, fill='black', outline='white', width=3)
    _14 = rouletteTable.create_rectangle(146,65,173,115, fill=redColor, outline='white', width=3)
    _15 = rouletteTable.create_rectangle(146,15,173,65, fill='black', outline='white', width=3)
    
    _16 = rouletteTable.create_rectangle(173,115,200,165, fill=redColor, outline='white', width=3)
    _17 = rouletteTable.create_rectangle(173,65,200,115, fill='black', outline='white', width=3)
    _18 = rouletteTable.create_rectangle(173,15,200,65, fill=redColor, outline='white', width=3)
    
    _19 = rouletteTable.create_rectangle(200,115,227,165, fill=redColor, outline='white', width=3)
    _20 = rouletteTable.create_rectangle(200,65,227,115, fill='black', outline='white', width=3)
    _21 = rouletteTable.create_rectangle(200,15,227,65, fill=redColor, outline='white', width=3)
        
    _22 = rouletteTable.create_rectangle(227,115,254,165, fill='black', outline='white', width=3)
    _23 = rouletteTable.create_rectangle(227,65,254,115, fill=redColor, outline='white', width=3)
    _24 = rouletteTable.create_rectangle(227,15,254,65, fill='black', outline='white', width=3)
    
    _25 = rouletteTable.create_rectangle(254,115,281,165, fill=redColor, outline='white', width=3)
    _26 = rouletteTable.create_rectangle(254,65,281,115, fill='black', outline='white', width=3)
    _27 = rouletteTable.create_rectangle(254,15,281,65, fill=redColor, outline='white', width=3)
    
    _28 = rouletteTable.create_rectangle(281,115,308,165, fill='black', outline='white', width=3)
    _29 = rouletteTable.create_rectangle(281,65,308,115, fill='black', outline='white', width=3)
    _30 = rouletteTable.create_rectangle(281,15,308,65, fill=redColor, outline='white', width=3)
    
    _31 = rouletteTable.create_rectangle(308,115,335,165, fill='black', outline='white', width=3)
    _32 = rouletteTable.create_rectangle(308,65,335,115, fill=redColor, outline='white', width=3)
    _33 = rouletteTable.create_rectangle(308,15,335,65, fill='black', outline='white', width=3)
    
    _34 = rouletteTable.create_rectangle(335,115,362,165, fill=redColor, outline='white', width=3)
    _35 = rouletteTable.create_rectangle(335,65,362,115, fill='black', outline='white', width=3)
    _36 = rouletteTable.create_rectangle(335,15,362,65, fill=redColor, outline='white', width=3)
    
    first12 = rouletteTable.create_rectangle(38,165,146,190, fill=blueColor, outline='white', width=3)
    second12 = rouletteTable.create_rectangle(146,165,254,190, fill=blueColor, outline='white', width=3)
    third12 = rouletteTable.create_rectangle(254,165,362,190, fill=blueColor, outline='white', width=3)
    
    oneToEight = rouletteTable.create_rectangle(38,215,92,190, fill=blueColor, outline='white', width=3)
    even = rouletteTable.create_rectangle(92,215,146,190, fill=blueColor, outline='white', width=3)
    black = rouletteTable.create_rectangle(146,215,200,190, fill=blueColor, outline='white', width=3)
    red = rouletteTable.create_rectangle(200,215,254,190, fill=blueColor, outline='white', width=3)
    odd = rouletteTable.create_rectangle(254,215,308,190, fill=blueColor, outline='white', width=3)
    nineteenToThirtysix = rouletteTable.create_rectangle(308,215,362,190, fill=blueColor, outline='white', width=3)
    
    twoToOne_1 = rouletteTable.create_rectangle(362,115,389,165, fill=blueColor, outline='white', width=3)
    twoToOne_2 = rouletteTable.create_rectangle(362,65,389,115, fill=blueColor, outline='white', width=3)
    twoToOne_3 = rouletteTable.create_rectangle(362,15,389,65, fill=blueColor, outline='white', width=3)

    #Text to go into each rectangle.
    rouletteTable.create_text(25, 57, text='00', fill='white')
    rouletteTable.create_text(25, 132, text='0', fill='white')

    rouletteTable.create_text(52, 140, text='1', fill='white')
    rouletteTable.create_text(52, 90, text='2', fill='white')
    rouletteTable.create_text(52, 40, text='3', fill='white')

    rouletteTable.create_text(79, 140, text='4', fill='white')
    rouletteTable.create_text(79, 90, text='5', fill='white')
    rouletteTable.create_text(79, 40, text='6', fill='white')

    rouletteTable.create_text(106, 140, text='7', fill='white')
    rouletteTable.create_text(106, 90, text='8', fill='white')
    rouletteTable.create_text(106, 40, text='9', fill='white')

    rouletteTable.create_text(133, 140, text='10', fill='white')
    rouletteTable.create_text(133, 90, text='11', fill='white')
    rouletteTable.create_text(133, 40, text='12', fill='white')

    rouletteTable.create_text(160, 140, text='13', fill='white')
    rouletteTable.create_text(160, 90, text='14', fill='white')
    rouletteTable.create_text(160, 40, text='15', fill='white')

    rouletteTable.create_text(187, 140, text='16', fill='white')
    rouletteTable.create_text(187, 90, text='17', fill='white')
    rouletteTable.create_text(187, 40, text='18', fill='white')

    rouletteTable.create_text(214, 140, text='19', fill='white')
    rouletteTable.create_text(214, 90, text='20', fill='white')
    rouletteTable.create_text(214, 40, text='21', fill='white')

    rouletteTable.create_text(241, 140, text='22', fill='white')
    rouletteTable.create_text(241, 90, text='23', fill='white')
    rouletteTable.create_text(241, 40, text='24', fill='white')

    rouletteTable.create_text(268, 140, text='25', fill='white')
    rouletteTable.create_text(268, 90, text='26', fill='white')
    rouletteTable.create_text(268, 40, text='27', fill='white')

    rouletteTable.create_text(295, 140, text='28', fill='white')
    rouletteTable.create_text(295, 90, text='29', fill='white')
    rouletteTable.create_text(295, 40, text='30', fill='white')

    rouletteTable.create_text(322, 140, text='31', fill='white')
    rouletteTable.create_text(322, 90, text='32', fill='white')
    rouletteTable.create_text(322, 40, text='33', fill='white')

    rouletteTable.create_text(349, 140, text='34', fill='white')
    rouletteTable.create_text(349, 90, text='35', fill='white')
    rouletteTable.create_text(349, 40, text='36', fill='white')

    rouletteTable.create_text(92, 178, text='~First 12~', fill='white')
    rouletteTable.create_text(200, 178, text='~Second 12~', fill='white')
    rouletteTable.create_text(308, 178, text='~Third 12~', fill='white')

    rouletteTable.create_text(65, 205, text='1 to 18', fill='white')
    rouletteTable.create_text(119, 205, text='Even', fill='white')
    rouletteTable.create_rectangle(153,197,193,210, fill='black', outline='white', width=2)
    rouletteTable.create_rectangle(207,197,247,210, fill=redColor, outline='white', width=2)
    rouletteTable.create_text(281, 205, text='Odd', fill='white')
    rouletteTable.create_text(335, 205, text='19 to 36', fill='white')

    rouletteTable.create_text(376, 140, text='2\nto\n1', fill='white')
    rouletteTable.create_text(376, 90, text='2\nto\n1', fill='white')
    rouletteTable.create_text(376, 40, text='2\nto\n1', fill='white')

    #Separate information window button.
    infoButton = Button(root, text = 'Info')
    infoButton.config(command = infoWindow)
    infoButton.pack(side=BOTTOM)    

    #############################################
    ##                                         ##
    ## This is where the problem is.           ##
    ##                                         ##
    #############################################

    currentFunds = CurrentFunds()
    currentFunds.getValue()
                                     
    while currentFunds.getValue() > 0:
        rouletteTable.bind("<Button-1>", click)
        currentFundsLabel.config(text = "You currently have $" + str(currentFunds.getValue()))                                   
        currentFunds.getValue()
        print currentFunds.getValue()
    #############################################
    ##                                         ##
    ## This is where the problem is.           ##
    ##                                         ##
    #############################################
    
def addInfo(root):
    #Text to appear in information window.
    infoFrame = Frame(root)
    infoFrame.pack()
    
    greetLabel = Label(infoFrame, text = 'This is a simulation of the casino game "Roulette" \n')
    greetLabel.pack()

    requirementsLabel = Label(infoFrame, text = 'In this simulation you can play until you either:\n' \
                       '   -Get tired of playing \n' \
                       '   -Run out of money \n')
    requirementsLabel.pack()

    rulesLabel1 = Label(root, text = 'You have been given $300 to start playing. \n' \
                        'First enter the amount you would like to bid in the \n' \
                        'entry box, then use your mouse to click the area of \n' \
                        'the Roulette table that you would like to bid on.\n' \
                        'Once you click the table, the Roulette will spin. \n')
    rulesLabel1.pack()

def outsideTable(root):
    
    def stop():
        root.destroy()
        
    resultLabel = Label(root, text = 'You did not click inside the table')
    resultLabel.pack()

    closeButton = Button(root, text = 'Close')
    closeButton.config(command = stop)
    closeButton.pack()

def invalidBet(root):
    
    def stop():
        root.destroy()
        
    resultLabel = Label(root, text = 'Invalid bet amount')
    resultLabel.pack()

    closeButton = Button(root, text = 'Close')
    closeButton.config(command = stop)
    closeButton.pack()

def main():
    root = Tk()
    root.title('Roulette')
    root.geometry('400x335')
    root.config(bg = 'dark green')
    addWidgets(root)
    root.mainloop()

main()

700 loc for a simple roulette game? I guess you could shorten it a bit :icon_wink:

if spin == 3 or spin == 4 or spin == 5 or spin == 6 or spin == 7 or spin == 8 \
or spin == 9 or spin == 10 or spin == 11 or spin == 12 or spin == 13 or spin == 14:

What about

if spin in [3,4,5,6,7,8,9,10,11,12,13,14]:
# or
if spin in range(3,15):

The next one:

if result == 1:
    resultLabel.config(text = 'The Roulette landed on 00')
elif result == 2:
    resultLabel.config(text = 'The Roulette landed on 0')
...

The first 2 lines are ok, but all the following elif clauses can be written in one line of code. Hint: The number shown is always result - 2 :icon_wink:

Anyway. I don't want to read all those 700 lines to find your error, and I guess no one else here does. My suggestion: throw the code away and start again. Make it simpler at first (maybe a roulette with only 3 numbers?), build it up step by step and test often. So you find your errors earlyer and easier.

Hope this helps.

I appreciate your help, but I'm almost positive that I have pinpointed where the problem is, I just have no idea how to solve it.

The problem is in the while loop. Everytime you click the mouse, the program should deduct the bet amount from the total current funds. To do this normally, I needed a while loop, with an accumulator for current funds, because without the while loop, the program would just keep resetting the accumulator to 300 everytime the mouse was clicked.

So logically, I put the line of code:

rouletteTable.bind("<Button-1>", click)

Inside the while loop. However, after I put that into the while loop, it becomes an infinite loop, and I don't know why

currentFunds = CurrentFunds()
currentFunds.getValue()
                                     
while currentFunds.getValue() > 0:
    rouletteTable.bind("<Button-1>", click)
    currentFundsLabel.config(text = "You currently have $" + str(currentFunds.getValue()))                                   
    currentFunds.getValue()
    print currentFunds.getValue()

Ok, now I see the problem (you marked it quite well :icon_smile:).
Well, there is nothing that would stop the while loop. Line 5 just binds the left mouse button to click, that doesn't mean that the program does nothing but wait for this click. It binds the button event, ok, next line ...
I also don't quite understand lines 2 and 7. currentFunds.getValue() returns something, but you ignore it.
IMO you don't need the loop. When you click, call a function that does the following:
* get the current funds
* run the roulette
* change the current funds

Here is a (silly) mini example of what I mean:

import Tkinter as tk

class Current:
    def __init__(self):
        self.value = 0

def click():
    # get the curren value
    current = curr.value 
    # do something, run the roulette, whatever. Here we just change the label
    amount.configure(text="%s" % (current+1))
    # change the current value
    curr.value += 1

curr = Current()
root = tk.Tk()

amount = tk.Label(text="0")
amount.pack()
tk.Button(text="+1", command=click).pack()

root.mainloop()

Hope this helps ... really :icon_smile:

It works!

Thank you everyone SO much!!!
I had been working on this problem almost ALL weekend, and it had been driving me insane.

I can't tell you all how grateful I am!

=D

Okay, I am just putting the finishing touches on my program, and I ran into another problem, although this one is relatively insignificant.

Once the player runs out of money, I have a "game over" window that appears to notify them that they are now broke.

In this "Game Over" window, I wanted to either:
a) Once they hit the close button, both windows will close (the game over window AND the actual game interface)
b) Give them a choice to keep playing if they wanted to.

I liked the second idea better, because in that situation, they would have two options to choose from, closing the game, or to keep playing.

I tried to implement this idea with this code:

def endGame(root):
        def play():
            curr = CurrentFunds()
            root.destroy()
            curr.setValue(300)

        def stop():
            root.destroy()

        endLabel = Label(root, text = "I'm sorry, you have run out of money. \n" \
                         "Better luck next time!")
        endLabel.pack()
        
        closeButton = Button(root, text = 'Close')
        closeButton.config(command = stop)
        closeButton.pack(side=BOTTOM)

        retryButton = Button(root, text = 'Play Again?')
        retryButton.config(command = play)
        retryButton.pack(side=BOTTOM)

However, I am not sure how to close BOTH windows if they hit close, and once I set the value back to 300, it doesnt seem to reset itself in the way that I would hope.

Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.