本文整理汇总了Python中tkinter.Canvas.unbind方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.unbind方法的具体用法?Python Canvas.unbind怎么用?Python Canvas.unbind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.unbind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import unbind [as 别名]
class Scene(object):
def __init__(self, master, device, mouse_tracking=False):
self.master = master
self.device = device
self.frame = tk.Frame(master)
self.feedbackButton = tk.Button(
self.frame,
text="Feedback window",
width=25,
command=self.open_feedback
)
self.feedbackButton.pack()
self.explore_canvas = Canvas(master, width=500, height=500)
self.explore_canvas.pack()
if mouse_tracking:
self.explore_canvas.bind(
'<Motion>', lambda event, device=device: motion(event, device))
self.enable_position_feedback()
self.network_drawings = []
self.frame.pack()
self.app = None
self.update()
def activate_key_listening(self, listener):
# Will focus frame, needed for key binding
self.explore_canvas.bind(
"<Button-1>",
lambda event,
frame=self.explore_canvas: focus(event, frame)
)
self.explore_canvas.bind(
"<Key>",
lambda event: listener.update_pressed_key(str(event.char))
)
def desactivate_key_listening(self):
self.explore_canvas.unbind("<Button-1>")
self.explore_canvas.unbind("<Key>")
def enable_position_feedback(self):
self.device_cursor = self.explore_canvas.create_oval(
self.device.position.x - 2.5, self.device.position.y - 2.5,
self.device.position.x + 2.5, self.device.position.y + 2.5)
def draw_network(self, network):
self.explore_canvas.delete('all')
self.enable_position_feedback()
for node in network.nodes:
pos_x = node.x - 5
pos_y = node.y - 5
self.explore_canvas.create_oval(
pos_x, pos_y, pos_x + 10, pos_y + 10, fill="blue")
for link in network.links:
pt_a = link.first
pt_b = link.sec
self.explore_canvas.create_line(
pt_a.x, pt_a.y, pt_b.x, pt_b.y)
def update(self):
coords = self.explore_canvas.coords(self.device_cursor)
if len(coords) <= 3:
self.master.after(50, self.update)
return
center = ((coords[0] + coords[2]) / 2, (coords[1] + coords[3]) / 2)
self.explore_canvas.move(
self.device_cursor,
self.device.position.x - center[0],
self.device.position.y - center[1])
if self.app and not self.app.closed:
self.app.update()
self.master.after(50, self.update)
def open_feedback(self):
self.feedbackWindow = tk.Toplevel(self.master)
self.app = Feedback(self.feedbackWindow, self.device)
示例2: Board
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import unbind [as 别名]
#.........这里部分代码省略.........
:param ancientSelectedCellTags: tags de la case anciennement selectionnée
:return: longueur
"""
departJ=int(ancientSelectedCellTags[0][1])
departI=int(ancientSelectedCellTags[0][2])
length=None
if(departI!=i):
isDiago=abs(j-departJ)/abs(i-departI)
if(isDiago==1):#la case d'arrivée se trouve sur la diagonale
length=( ((j-departJ)**2) + ((i-departI)**2) )**(1/2) #recherche de l'hypothenuse
length/=(2)**(1/2) #divisé par racine de 2 car l'hypothenuse d'un triangle avec 2 coté de longueur 1 = racine de 2
return(length)
def findDirection(self,i,j,ancientSelectedCellTags):
"""
:param i: coordonnée de la ligne
:param j: coordonnée de la colonne
:param ancientSelectedCellTags: tags de la case anciennement selectionnée
:return: direction
"""
dirI=(i-int(ancientSelectedCellTags[0][2]))/abs(i-int(ancientSelectedCellTags[0][2]))
dirJ=(j-int(ancientSelectedCellTags[0][1]))/abs(j-int(ancientSelectedCellTags[0][1]))
direction="L"
if (dirJ==self.player): direction="R"
if(dirI==self.player): direction+="B"
return(direction)
def enfOfGame(self):
end=dr.checkEndOfGame(self.logicBoard,self.player)
if (end is False): return #le jeu n'est pas fini
self.guiBoard.unbind("<Button -1>")
if(end!=0):
winner="RED PLAYER" if end==1 else "BLUE PLAYER"
text=winner + " WON"
else:
text = "DRAW"
FixedLabel(self,text,16,6)
def changePlayer(self,cellId,i,j):
"""
:param cellId: Id du dernier pion joué
:param i: coordonnée de la ligne
:param j: coordonnée de la colonn
"""
self.player=-self.player
val="RED" if self.player ==1 else "BLUE"
self.currentVariableLabel.setVar(val)
self.hasPlayed=False
self.hasCaptured=False
dr.becomeKing(self.logicBoard,j,i)
self.enfOfGame()
if (dr.isKing(self.logicBoard,j,i)): self.guiBoard.itemconfig(cellId,outline="gold",width=2)
def coordToLetter(self,j):
"""
:param j: coordonée de la colonne
:return: coordonnée de la colonne en format lettre
"""
return(chr(int(j)+97))