, height=500, bg='blue') frame.bind("<Key>", key) frame.bind("<Button-1>", callback_1) frame.bind("<Button
onLeftClick) # mouse button clicks widget.bind('<Button-3>', onRightClick) widget.bind('<Button
<button id="btn-1">按钮1</button> <button id="btn-2">按钮2</button> <script> // 假如想通过点击 Button-1 触发 Button
-1>', printcoords) # 创建二个 Button,并将它与中键事件绑定 bt2 = tk.Button(root, text='middle button') bt2.bind('<Button
action=click&id=button1); display: none; } .button-2:active::after { content: url(.
Tkinter 提供了几种常见的鼠标事件,如 <Button-1> (左键单击)、 <Button-2> (中键单击)、 <Button-3> (右键单击)等。
pack(side="top") btn1.pack(side="top") Mainform.mainloop() tkinter常见事件类型 常见的 tkinter 事件类型包括:Button-1、Button
tkinterwin = tkinter.Tk()win.title("Label标签")win.geometry("300x300+300+300")#<Button-1>鼠标左键#<Button-3>鼠标右键#<Button
pack() window.bind("Button-1", left_click) window.bind("Button-2", middle_click) window.bind("Button-
self.canvas.bind('<ButtonRelease-1>',self.Draw) #绑定事件到左键 44 self.canvas.bind('<Button
self.canvas.bind('<ButtonRelease-1>',self.Draw) #绑定事件到左键 44 self.canvas.bind('<Button
button:nth-of-type(3){animation:button-1 2s infinite reverse}.keyboard__button:nth-of-type(5){animation:button :40%}}@keyframes button-1{0%{background-color:#3cfbfe}100%,50%{background-color:#b8acfb}}@keyframes button
以便能够捕获键盘事件 root.focus_set() root.mainloop() 4.2 常用事件类型 下面是一些常用的Tkinter事件类型: 4.2.1 鼠标事件 <Button-1>:鼠标左键点击 <Button ) position_label.pack(pady=5) # 绑定鼠标事件 canvas.bind("<Button-1>", on_click) # 鼠标左键点击 canvas.bind("<Button
它们之间用减号分隔,常见事件代码见下表: 事件 事件代码 备注 单击鼠标左键 <ButtonPress-1> 可简写为<Button-1> 或 <1> 单击鼠标中键 <ButtonPress-2> 可简写为<Button
鼠标按钮单击还有其他事件,包括"<Button-2>"鼠标中键和"<Button-3>"鼠标右键。 command 每个Button小部件都有一个command可以分配给函数的属性。