从艺术设计图形绘图板输入

Input from a Art Design Graphic Drawing Tablet

我有一个小的、未开发的白板应用程序,目前使用 tkinter 函数接收来自鼠标的输入,例如 widget.bind(<'x'>, handler)

这是代码,如果对您有帮助的话:

---开始代码---

from tkinter import *  # imports required files

canvas_width = 500
canvas_height = 500


def get_width():
    return canvas_width


def get_height():
    return canvas_height


def paint(event):
    color = "black"
    x1, y1 = (event.x - 1), (event.y - 1)
    x2, y2 = (event.x + 1), (event.y + 1)
    w.create_oval(x1, y1, x2, y2, fill=color)




def clear(event):  # experimental helper function
    print('Clearing whiteboard!(Invoked by <Button-3>, a right click.)')
    color = '#FFFFFF'
    w.create_rectangle(0, 0, canvas_width, canvas_height, fill=color)


master = Tk()
master.title("Painting using Ovals")
w = Canvas(master,
           width=canvas_width,
           height=canvas_height)
w.pack(expand=YES, fill=BOTH)
w.bind("<Button-3>", clear)
w.bind("<B1-Motion>", paint)

message = Label(master, text="Left-Click and Drag the mouse to draw, Right-click to clear the board")
message.pack(side=BOTTOM)

mainloop()

---结束代码---

我想知道的是,如果我将 Art Design Graphic Drawing Tablet 插入我的计算机,tkinter 是否仍然能够检测到点击?按下垫子是否与用鼠标左键单击具有相同的效果?可以按下什么来调用绘图板上鼠标上的右键单击或移动滚轮的等价物?我知道这可能因程序和平板电脑而异,但任何信息都会非常有帮助!

如果您能够使用任何设备 click/drag/scroll 在您计算机上的任何应用程序(如此网络浏览器)上,那么它将生成与 tkinter 将响应的事件相同的事件。

如果平板电脑没有按预期运行,您可以绑定一个通用 <Button> 回调并通过查看事件来检查它是哪个按钮:

def callback(event):
    print(event.num)#I have always seen one of (1,2,3,'??')