python问题:tkinter监听canvas的鼠标滚轮滚动事件

aiiiq 2009-02-02 05:19:24
这段代码在按下滚轮时能接收到事件,但是滚动滚轮时没反应

大侠快站出来吧!给个wxpython的例子也行啊!


from Tkinter import *

class Test(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
Pack.config(self)
self.draw = Canvas(self)
self.draw.pack()
self.draw.bind("<MouseWheel>", self.mouseWheel)
self.draw.bind("<Button-2>", self.mouseWheel)

def mouseWheel(self, event):
self.draw.create_rectangle(50, 50, 100, 100)

root = Tk()
test = Test(master=root)
test.mainloop()
...全文
718 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxl2002 2011-03-22
  • 打赏
  • 举报
回复
在Tkinter中是怎么解决的呢?
liushulin 2009-03-02
  • 打赏
  • 举报
回复
tkinter监听canvas的鼠标滚轮滚动事件

http://wedliu.blogspot.com/2009/03/using-mouse-wheel-with-tkinter-python.html
eynStudio 2009-02-07
  • 打赏
  • 举报
回复
好样的!
aiiiq 2009-02-04
  • 打赏
  • 举报
回复
自己动手解决


import wx

class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.panel = wx.Panel(self)
self.panel.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)

def OnMouseWheel(self, event):
self.dc = wx.ClientDC(self.panel)
self.dc.SetPen(wx.Pen("red", 1))
self.dc.DrawLine(100, 1, 100, 100)

app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧