Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_mouse_plus_key.py
- from tkinter import *
- root = Tk()
- class Cv(): 0
- cv = Cv()
- cv.x = cv.y = 0
- cv.ctrl = 0
- def draw():
- canvas.create_oval(cv.x-5, cv.y-5, cv.x+5, cv.y+5, fill='black')
- def release(e):
- key = e.keysym
- print("RELEASED:", key)
- if key in ('Control_L'):
- canvas.unbind('<B1-Motion>')
- def onLeftClick(e):
- cv.x = e.x
- cv.y = e.y
- draw()
- def onLeftDrag(e):
- cv.x = e.x
- cv.y = e.y
- if 1: # cv.ctrl:
- draw()
- def onCTRLdown(e):
- key = e.keysym
- print("PRESSED:", key)
- canvas.bind('<B1-Motion>', onLeftDrag)
- canvas = Canvas(root, width=400, height=400, bg='white')
- canvas.pack()
- # needed to detect all the keyboard events <<<<<
- canvas.focus_set()
- canvas.bind('<Button-1>', onLeftClick)
- canvas.bind("<KeyRelease>", release)
- canvas.bind("<KeyPress>", onCTRLdown)
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement