-1

I'm currently "programming" a simple calculator in Python, created all the labels and the general "outlook" of the calculator.

I need to create binding functions so that when a label e.g. "1" is pressed it is added to the string that is to be executed.

I know how to create a binding function that emulates all three button clicks (), enter and left and right arrows but I have no idea how to define the numbers and symbols, so, if someone had a reference sheet with all the numbers, symbols and letters it would be great.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

1

In Tkinter, most event strings for keyboard presses simply correspond to the symbol of the key. For example, to trigger an event when the "1" key is pressed, do:

root.bind("1", some_function)

(Note that this is different from root.bind("<1>", some_function) - the brackets indicate that the event is referring to the first mouse button.)

You can do the same for your typical artihmetic operators:

root.bind("+", some_function)
root.bind("-", some_function)
root.bind("*", some_function)
root.bind("/", some_function)
root.bind("=", some_function)
Kevin
  • 74,910
  • 12
  • 133
  • 166