Tkinter Using Two Keys At The Same Time
So tkinker can only use one key at a time. I am unable to say move to the left and up at the same time with this example. How would i go about doing it if I wanted to? import tkin
Solution 1:
Like this :
from Tkinter import *
root = Tk()
var = StringVar()
a_label = Label(root,textvariable = var ).pack()
history = []
def keyup(e):
print e.keycode
if e.keycode in history :
history.pop(history.index(e.keycode))
var.set(str(history))
def keydown(e):
if not e.keycode in history :
history.append(e.keycode)
var.set(str(history))
frame = Frame(root, width=200, height=200)
frame.bind("<KeyPress>", keydown)
frame.bind("<KeyRelease>", keyup)
frame.pack()
frame.focus_set()
root.mainloop()
Post a Comment for "Tkinter Using Two Keys At The Same Time"