I'm brand new to python (started today). I'm looking to automate something I do a lot of, so far I have 40% of what I need from googling and trying things out that I have found.
I'm trying to produce a counter, when I click the button, I want the counter to increase - I have this bit working...
from tkinter import *
root = Tk()
#Definitions of the fruit, links in with buttons with e1/2/3
def Appleadd_1(event):
value = int(e1.get())
value += 1
e1.delete(0, 'end')
e1.insert(0, value)
def Pearadd_1():
value = int(e2.get())
value += 1
e2.delete(0, 'end')
e2.insert(0, value)
def Grapeadd_1():
value = int(e3.get())
value += 1
e3.delete(0, 'end')
e3.insert(0, value)
#text boxes for counts
e1 = tk.Entry(root)
e1.insert(0, 0)
e1.pack()
e2 = tk.Entry(root)
e2.insert(0, 0)
e2.pack()
e3 = tk.Entry(root)
e3.insert(0, 0)
e3.pack()
#buttons
bt1 = tk.Button(root, text="Apples", command=Appleadd_1)
bt1.bind("<q>" , )
bt1.pack()
bt2 = tk.Button(root, text="Pears", command=Pearadd_1)
bt2.pack()
bt2.bind("1", bt2)
bt3 = tk.Button(root, text="Grapes", command=Grapeadd_1)
bt3.pack()
root.mainloop()
Although it looks ugly, it works and I have just found how to place things instead of using pack()
One thing I can't get to work, is binding a keyboard key to the buttons I have created. Is it possible?
Any help would be greatly appreciated!
Thank you