本文整理汇总了Python中Tkinter.Tk.bind_all方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.bind_all方法的具体用法?Python Tk.bind_all怎么用?Python Tk.bind_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Tk
的用法示例。
在下文中一共展示了Tk.bind_all方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind_all [as 别名]
def __init__(self, parent, title, width, height):
"""
Arguments:
*parent*
Parent Tk window or Null for none.
*title*
Title for window.
*width, height*
Dimensions of window.
"""
display = os.environ.get('DISPLAY', None)
if not display:
os.environ['DISPLAY'] = ':0'
Tk.__init__(self, parent)
def mouseclick_callback(event):
if not self.resized:
self.ev = 'click'
self.x = event.x
self.y = event.y
def mousemove_callback(event):
if not self.resized:
self.ev = 'move'
self.x = event.x
self.y = event.y
def mousewheel_callback(event):
if not self.resized:
self.ev = 'wheel'
self.num = event.num
self.delta = event.delta
def drag_callback(event):
if not self.resized:
self.ev = 'drag'
self.x = event.x
self.y = event.y
mouserot = event.x
def resize_callback(event):
self.ev = 'resized'
self.winx = self.winfo_x()
self.winy = self.winfo_y()
self.width = event.width
self.height = event.height
self.resized = True
def key_callback(event):
if not self.resized:
self.ev = 'key'
self.key = event.keysym
self.char = event.char
Tk.bind(self, '<Button-1>', mouseclick_callback)
Tk.bind(self, '<B1-Motion>', drag_callback)
Tk.bind(self, '<Motion>', mousemove_callback)
Tk.bind(self, '<MouseWheel>', mousewheel_callback)
Tk.bind(self, '<Configure>', resize_callback)
Tk.bind_all(self, '<Key>', key_callback)
Tk.geometry(self, str(width) + 'x' + str(height))
self.title(title)
self.ev = ''
self.resized = False