首页 > 编程知识 正文

python实战案例,pygame鼠标点击事件

时间:2023-05-06 13:09:59 阅读:111243 作者:3374

更新:这是版本问题。 单击Python3.6.1时不会触发此事件,但可以在当前测试的2.7上运行。 在

更新: Bryan的回答确实解决了我的事件不能正常工作的问题,但在我的3.6.1版python中,事件按下时不启动的问题仍然是个问题。 在

Python版本=3.6.1(v3.6.1:69c0db5,mar 212017,18336041:36 ) [ mscv.190064 bit ] amd64 ]

您要创建一个事件处理程序,在按住鼠标按钮的同时执行一次又一次的操作。 我搜索了文档和互联网,但是找不到关于按鼠标左键的任何参考。 在

有专门用于按鼠标左键的活动吗? release有偶数,但单击保留的事件没有seam。 在

以防万一,我尝试了所有和那个同义的事件,但没有运气。 事件仅在发布时触发,按所需向下单击时不会触发。 甚至不需要持续按下按钮的活动。 需要偶数的向下按钮。 在

找不到文档,欢迎使用文档。 在

更新:

示例代码如下所示。 只有在松开按钮时才会打印。 请注意,您要按滚动条上的箭头按钮更改滚动速度。 在

滚动条与按滚动箭头的方法和按钮不同吗? 在import tkinter as tk上

root=tk.Tk (

textbox=tk.text(root,height=10 ) )。

textbox.grid(row=0,column=0) )。

scrolling=False

yscroll=tk.scrollbar(root,command=textbox.yview,orient='vertical ',repeatinterval=10,repeatdelay=30 )

textbox.configure (yscrollcommand=y scroll.set ) )。

yscroll.grid(row=0,column=1,sticky='ns ' ) ) )。

forIinrange(1000 ) :

textbox.insert(tk.end,' {}n'.format(I ) )

efscrolling_active(arrow ) :

全球滚动

root.bind (',stop_scrolling ) )

是打印(阵列)

if scrolling==True:

if arrow=='arrow1':

textbox.tk.call(textbox._w,' yview ',' scroll ',-100,' units ' ) )

if arrow=='arrow2':

textbox.tk.call(textbox._w,' yview ',' scroll ',100,' units ' ) )

root.after(100,lambdaa=arrow : scrolling _ active ) a ) )

defstart_scrolling(event ) :

全球滚动

scrolling=True

scrolling _ active (y scroll.identify (event.x,event.y ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )。

def stop_scrolling () :

全球滚动

scrolling=False

yscroll.bind (',start_scrolling )。

root.mainloop (

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。