Tkinter button commands

15 views Asked by At

I'm trying to make a keyboard that prints the letter which you press, but whenever you press any button it always types "m"

import tkinter as tk

Alphabet = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
xValues = [28,53,78,103,128,153,178,203,228,253,40,65,90,115,140,165,190,215,240,53,78,103,128,153,178,203]
yValues = [310,310,310,310,310,310,310,310,310,310,335,335,335,335,335,335,335,335,335,360,360,360,360,360,360,360,360]

Win = False
window = tk.Tk()
window.title("MOSLE")
window.geometry("300x410")


frame = tk.Frame(master=window,bg="black")
frame.pack(fill=tk.BOTH,expand=True)

Buttons = []

for x in range(26):
    Button = tk.Button(master=frame,bg="light grey",fg="white",width=2,height=1,text=Alphabet[x].upper(),highlightthickness=0,borderwidth=0,command= lambda: TypeLetter(Alphabet[x]))
    Button.place(x=xValues[x],y=yValues[x])
    Buttons.append(Button)


BackspaceButton = tk.Button(master=frame,bg="light grey",fg="white",width=4,height=1,text="⌫",highlightthickness=0,borderwidth=0)
BackspaceButton.place(x=228,y=360)
EnterButton = tk.Button(master=frame,bg="light grey",fg="white",width=6,height=1,text="Enter.",highlightthickness=0,borderwidth=0)
EnterButton.place(x=130,y=385)

def TypeLetter(Letter):
    print(Letter) 

I tried configuring the buttons in a second for loop after having placed them, it gave the exact same result.

0

There are 0 answers