Nov-22-2019, 11:03 PM
I am creating a tkinter program. There is always one button - 'Place' - on the screen. When that button is clicked I want two more buttons to appear and the user is only supposed to click one of them. For some reason this is not working and I am getting a logic error. Right now when the user clicks on 'Place', the commands of the other two buttons are automatically accessed. I don't want the commands on these buttons accessed until the user clicks on them.
Here is my code:
Here is my code:
python & tkinter from tkinter import * from tkinter import scrolledtext # Window window = Tk() window.geometry("750x500") window.configure(background='gray') window.title("Fantasy Betting Log") # Bank bank = 100 bankLbl = Label(window, text="Bank: " + str(bank)) bankLbl.place(x=0, y=0) # Functions def win(wager, odds): if int(odds) > 0: return float(wager) * float(odds) / 100 if int(odds) < 0: return float(wager) * 100 / abs(float(odds)) def winClicked(name, wager, odds): log.insert(INSERT,'WIN - ' + name + ' won you ' + str(win(wager, odds))) log.insert(END, "$ \n") def loseClicked(name, wager): log.insert(INSERT,'LOSS - ' + name + ' lost you ' + str(wager)) log.insert(END, "$ \n") counter = 0 def newLiveBet(name, wager, odds): global counter liveBet = Label(window, text= name + " - Wager: " + wager + ", Odds: " + odds) liveBet.place(x=10, y=(300 + (30 * counter))) winButton = Button(window, text="Win", width=3, bg="white", fg="green", command=winClicked(name,wager, odds)) winButton.place(x= 400, y = (300 + (30 * counter))) loseButton = Button(window, text="Lose", width=3, bg="white", fg="red", command=loseClicked(name, wager)) loseButton.place(x= 450, y = (300 + (30 * counter))) counter += 1 def placeClicked(): name = betName.get() wager = wagerAmt.get() odds = oddsAmt.get() betName.delete(0, END) wagerAmt.delete(0, END) oddsAmt.delete(0, END) newLiveBet(name, wager, odds) #Theres more code here but irrelevant to question window.mainloop()So essentially when the button 'place' is clicked, 'winClicked()' and 'loseClicked' also act like they were clicked when all I want is for them to appear on the screen.