新聞中心
一、概述

創(chuàng)新互聯(lián)公司是網(wǎng)站建設(shè)專家,致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,專業(yè)領(lǐng)域包括成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、電商網(wǎng)站制作開發(fā)、小程序開發(fā)、微信營銷、系統(tǒng)平臺開發(fā),與其他網(wǎng)站設(shè)計(jì)及系統(tǒng)開發(fā)公司不同,我們的整合解決方案結(jié)合了恒基網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗(yàn)和互聯(lián)網(wǎng)整合營銷的理念,并將策略和執(zhí)行緊密結(jié)合,且不斷評估并優(yōu)化我們的方案,為客戶提供全方位的互聯(lián)網(wǎng)品牌整合方案!
一個(gè) GUI 應(yīng)用整個(gè)生命周期都處在一個(gè)消息循環(huán) (eventloop) 中。 它等待事件的發(fā)生, 并作出相應(yīng)的處理。Tkinter 提供了用以處理相關(guān)事件的機(jī)制. 處理函數(shù)可被綁定給各個(gè)控件的各種事件。
widget.bind(event, handler)
如果相關(guān)事件發(fā)生, handler 函數(shù)會被觸發(fā) , 事件對象event 會傳遞給 handler 函數(shù)。二
二、鼠標(biāo)和鍵盤事件
三、event 對象常用屬性
四、鼠標(biāo)事件和鍵盤事件用法測量
#coding=utf-8
from tkinter import *
class application(Frame):
def __init__(self,master):
super().__init__(master)
self.master=master
self.pack()
self.createWidget()
def createWidget(self):
self.canvas = Canvas(self,width=200,height=200,bg='green')
self.canvas.pack()
self.canvas.bind('',self.mouseTest)
self.canvas.bind('',self.test_drag)
self.canvas.bind('',self.keyboard_test)
self.canvas.bind('',self.press_a_test)
self.canvas.bind('KeyRelease-a',self.release_a_test)
def mouseTest(self,event):
print('鼠標(biāo)左鍵單機(jī)位置(相對于父容器):{0},{1}'.format(event.x,event.y))
print('鼠標(biāo)左鍵單擊位置(相對于屏幕):{0},{1}'.format(event.x_root,event.y_root))
print('事件綁定組件:{0}'.format(event.widget))
def test_drag(self,event):
self.canvas.create_oval(event.x,event.y,event.x+1,event.y+1)
def keyboard_test(self,event):
print('鍵的keycode:{0},char:{1},keysym:{2}'.format(event.keycode,event.char,event.keysym))
def press_a_test(self,event):
print('press a')
def release_a_test(self):
print('release a')
if __name__ == '__main__':
root = Tk()
root.geometry('500x300')
app=application(root)
root.mainloop() 標(biāo)題名稱:創(chuàng)新互聯(lián)Python教程:python中事件處理的方法
網(wǎng)站網(wǎng)址:http://www.dlmjj.cn/article/djsipcg.html


咨詢
建站咨詢
