For a on screen keyboard i need 26 buttons that all add one of the letters of the keyboard to a string. The first problem i got is that the string doesn't get saved after pressing a button. For example, User presses 'A', 'A' gets printed and should be stored. User now presses 'B', 'B' gets printed and 'A' is gone. The second problem is that the button only executes the function the first time. My code so far down below:
window = Tk()
window.attributes('-fullscreen', True)
window.configure(background='yellow')
master = Frame(window)
master.pack()
e = Entry(master)
e.pack()
e.focus_set()
nieuw_station = ""
def printanswer():
global nieuw_station
nieuw_station = e.get()
print(nieuw_station)
gekozen_station(nieuw_station)
invoeren = Button(master, text="Invoeren", width=10, command=printanswer)
invoeren.pack()
def letter_toevoegen(nieuw_station, letter):
nieuw_station += letter
print(nieuw_station)
return nieuw_station
a = Button(master, text="A", width=1, command=letter_toevoegen(nieuw_station, "a"))
a.pack()
b = Button(master, text="B", width=1, command=letter_toevoegen(nieuw_station, "b"))
b.pack()
window.mainloop()
The expected output would be: User presses 'A', 'A' get printed & stored. Now user presses 'B', 'AB' gets printed & stored. Lastly user presses 'C', 'ABC' now gets printed & stored. Whenever the user presses the 'invoeren' button it will get send to the next function with the new string as parameter(this actually works).