python之Gui程式設計事件繫結 2014 4 8

2022-09-16 10:54:13 字數 2304 閱讀 1828

place() 相對定位與絕對定位 相對定位 拖動會發生變化 絕對定位不會

from tkinter import *

root = tk()

# absolute positioning

button(root,text="absolute placement").place(x=20, y=10)

# relative positioning

button(root, text="relative").place(relx=0.5, rely=0.2, relwidth=0.5,

width=10, anchor = ne)

root.mainloop()

from tkinter import *

root = tk()

label(root, text='click at different\n locations in the frame below').pack()

def mycallback(event):

print dir(event)

print "you clicked at", event.x, event.y

#event.x event.y 橫座標縱座標

myframe = frame(root, bg='khaki', width=130, height=80)

myframe.bind("", mycallback)

#button-1是滑鼠左擊

#按下滑鼠b

##keyboard press of alt + ctrl + delete

myframe.pack()

root.mainloop()

myframe.bind("", mycallback)繫結事件

注意點:an event type (required): some common event types include button,

buttonrelease, keyrelease, keypress, focusin, focusout, le**e (mouse le**es

the widget ), and mousewheel.

an event modifier (optional): some common event modifiers include alt, any (used

like in ), control, double (used like in to

denote a double-click of the left mouse button ), lock, and shift

常用事件繫結

from tkinter import *

root = tk()

label(root, text='click at different\n locations in the frame below').pack()

def callback(event):

# print dir(event)

print "you clicked at", event.x, event.y

widget = frame(root, bg='khaki', width=130, height=80)

widget.bind("",callback) #bind widget to left mouse click

widget.bind("", callback) # bind to right mouse click

widget.bind("", callback)# bind to return(enter) key

widget.bind("", callback) #bind to focus in event

widget.bind("", callback)# bind to keypress a

widget.bind("", callback)# bind to capslockkeysym

widget.bind("", callback)# bind widget to f1 keysym

widget.bind("", callback)# bind to keypad number 5

widget.bind('', callback) # bind to motion over widget

widget.bind("", callback) # bind to any keypress

widget.pack()

root.mainloop()

Python之GUI程式設計

然後解壓到合適的路徑下,這裡解壓到了桌面。在cmd終端輸入以下 cd desktop cd 解壓的檔名 cd 一直到最後乙個子資料夾 cd python setup.py install 完成推薦使用最後一種方法。import easygui easygui.msgbox 嗨,你好呀 from ea...

jQuery事件之解綁事件

selector unbind eventtype handler eventobject 返回值 jquery 引數解釋 handler eventobject 型別 function 如果把在bind時傳遞的處理函式作為第二個引數,則只有這個特定的時間處理函式會被刪除。作用 bind 的反向操作...

《python核心程式設計》之GUI程式設計(續)

2018 6 19 這裡主要介紹gui的擴充套件。包括tix tk介面擴充套件 pmw python megawidgets thinter擴充套件 wxpython wxwidgets的python版本 以及pygtk gtk 的python版本 在前面的部落格裡面介紹了label,button的...