I'm trying to write a code for my GUI. I want a keyboard that adds a letter to the Entry widget. I'm close to it but the problem is that its adding to the entry only the letter 'a' when clicking on the buttons .
As you see in my code i added 'a' to the command. command=lambda: set_text('a') Ofcourse is this the reason why its printing 'a' only. But if i take letter from the forloop and make set_text(letter) its showing only H in the Entry widget.
I try'd also to remove the second loop change it to set_text(lst[count]) All buttons are adding now 'A' to the Entry.
Any idea what i'm doing wrong?
my code:
from tkinter import *
from ttk import *
def maakbuttons():
count = 0
lst = []
if count <= 7:
for letter in 'ABCDEFGH':
lst.append(letter)
for letter in lst:
Buttons = Button(master=root, text=letter, command=lambda: set_text('a'))
Buttons.place(x=20, y=30 +50 * count)
count+=1
def set_text(text):
a = e.get() + text
e.delete(0, len(e.get()))
e.insert(0, a)
def remove_letter():
last = len(e.get())-1
if last >= 0:
e.delete(last)
root= Tk()
a = root.wm_attributes('-fullscreen', 1)
e = Entry(root,width=10)
e.place(x=500, y=500)
maakbuttons()
root.mainloop()