Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Control the application using the keyboard
#1
Hello,
I have a problem with key control in my tkinter app. After pressing the key ("Enter", →, ←, +, Ctrl+S) I want to do my function. How do I set this control after pressing these keys? For example here is the scheme of the program (not my app):
from tkinter import*
app = Tk()

def MyFunction(x):   #I want to do this after pressing "Enter"
    print(x)

def MyFunction2(y):   #I want to do this after pressing "→"
    y = y + 1
    return y

def MyFunction3(z):   #I want to do this after pressing "Ctrl+S"
    return z**2

def MyFunction4(a):   #I want to do this after pressing "+"
    print(z*2)

app.mainloop()
Quote
#2
There are excellent sections on keyboard events in this manual: https://www.it.uu.se/edu/course/homepage...tkinterref
This is John Shipman's manual which used to be available at New Mexico Tech, but no longer.
It's rather dated, but still the best tkinter doc available (In my opinion)
see section 54 starting on page 157, all of the keyboard scan codes are in the table beginning on page 161
How to bind them in writeup prior to table
buran likes this post
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)