0
from tkinter import *
from tkinter.font import BOLD

root = Tk()
root.title("Calculator")
root.geometry("500x700")
root.config(bg="lightblue")
root.resizable(FALSE, FALSE)

outputwin = Canvas(root, width=455, height=100)
outputwin.place(x=20, y=20)

calcnum = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]


def calcfunc(args):
    if args == 0:
        print("0")
    elif args == 1:
        print("2")


count = 0

xpos = 40
ypos = 440





Button(root, text="0", padx=50, pady=30, font=("Helvetica", 15, BOLD), command=lambda: calcfunc(count)).place(x=190, y=575)
        
for x in range(0, 3):
    for x in range(0, 3):
        Button(root, text=calcnum[count], font=("Helvetica", 15, BOLD),padx=50, pady=30, command=lambda: calcfunc(count)).place(x=xpos, y=ypos)

        count +=1
        xpos += 150
        

    xpos = 40
    ypos -= 125

root.mainloop()

I am trying to find out how to use the lambda function to differentiate which button is clicked, however when i use my count variable, it does not register while passing in a regular number usually does work. Any help would be much appreciated.

Bryan Oakley
  • 341,422
  • 46
  • 489
  • 636

0 Answers0