本文整理汇总了Python中tkinter.Canvas.move方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.move方法的具体用法?Python Canvas.move怎么用?Python Canvas.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.move方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prgCanvas
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
#.........这里部分代码省略.........
lengthX = abs(mX-sX)
lengthY = abs(mY-sY)
if lengthX>0 and lengthY>0:
cX = lX/lengthX
cY = lY/lengthY
else:
cX,cY=1.0,1.0
print("MSH",cX,cY)
self.normalization = [abs(sX),abs(sY)]
self.mashtab = int(min(cX,cY)*0.9)
def transform(self,x,y,a,etalon):
"""
точка отсчета - в центре эталона
"""
new = list()
for item in etalon:
ca = cos(a)
sa = sin(a)
x2,y2 = item[0]-x, item[1]-y
new.append([x2*ca + y2*sa+x, x2*sa - y2*ca+y])
return new
def genfield(self):
x,y,d=0,1,2
self.canvas.delete("all")
for c in self.field:
cx = (c[x]+self.normalization[x])*self.mashtab+self.reper[x]
cy = (c[y]+self.normalization[y])*self.mashtab+self.reper[y]
print("filter",self.filter)
if self.flagDescription and self.filter==None:
tag = "BLACK"
_color1,_color2 = "black","black"
font = "Verdana 8"
self.canvas.create_text(cx,cy,anchor="nw",text=str(c[d][1]), fill=_color1,font=font,tag=("DESC",tag))
elif (not self.flagDescription) and self.filter==None:
tag = "BLACK"
_color1,_color2 = "black","black"
elif self.flagDescription and self.filter!=None and self.filter(c[d][2]):
_color1,_color2 = ["red","red"]
tag = "RED"
font = "Verdana 10 bold"
self.canvas.create_text(cx,cy,anchor="nw",text=str(c[d][1]), fill=_color1,font=font,tag=("DESC",tag))
elif self.flagDescription:
_color1,_color2 = "black","black"
tag = "BLACK"
# font = "Verdana 8"
# self.canvas.create_text(cx,cy,anchor="nw",text=str(c[d][1]), fill=_color1,font=font,tag=("DESC",tag))
pass
# здесь может быть выбор фигуры
# здесь может быть угол поворота
print("c",c)
if c[-2][0]=="25":
angle = radians(c[-1])
pattern = [[-3,-5.0],[3,-5.0],[0.0,3.0],[-3.0,-5.0]]
et = [[cx+item[0],cy+item[1]] for item in pattern]
new = self.transform(cx,cy,angle,et)
self.canvas.create_polygon(new,activefill="white",fill=_color2,tag=("FIG",tag))
else:
self.canvas.create_rectangle(cx-1,cy-1,cx+1,cy+1,outline=_color1,fill=_color2,tag=("FIG",tag))
self.canvas.tag_lower("RED")
def move(self,x,y):
#в группы
self.reper[0]+=x
self.reper[1]+=y
self.canvas.move("FIG",x,y)
self.canvas.move("DESC",x,y)
def load(self):
_p = prg(self.fileprogram)
_p.download()
_p.extract()
#вариант кода для загрузки информации о установке
self.field = [x[1:4]+[x[0]] for x in _p.progdigit if ("25" in x[3]) or ("107" in x[3])]
print(_p.progdigit)
#вариант кода для загрузки информации о дозировании:
# self.field.group = [x[1:4] for x in _p.progdigit if "107" in x[3]]
# print(self.field)
def paint(self):
self.load()
try:
self.setMashtab()
self.genfield()
except ZeroDivisionError:
print("Zero division")
except IndexError:
print("Index error")
#рисуем надпись
self.canvas.delete("all")
x,y = int(self.canvas["width"]),int(self.canvas["height"])
self.canvas.create_text(x//2,y//2,text="FILE IS CORRUPTED", font="Verdana 12 bold",fill="red",tag="del")
示例2: __init__
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
#.........这里部分代码省略.........
bj = self.balls[j]
tij = bi.ball_collision_time(bj)
self.PQ.insert(i, j, tij + self.time, self.balls[i].count, self.balls[j].count)
# self.ball_collision_times[i][j] = tij
# self.ball_collision_times[j][i] = tij
return
#update collision times is meant to update collision times of ball i with all
#walls (horizontal and vertical) and all other balls within the PQ array
def update_collision_times(self, i):
bi = self.balls[i]
tix = bi.horizontal_wall_collision_time(self.min_x, self.max_x)
tiy = bi.vertical_wall_collision_time(self.min_y, self.max_y)
self.PQ.insert(i, -1, tix + self.time,self.balls[i].count, -1)
self.PQ.insert(-1, i, tiy + self.time, -1, self.balls[i].count)
for j in np.arange(self.num_balls):
bj = self.balls[j]
tij = bi.ball_collision_time(bj) + self.time
if i > j:
self.PQ.insert(j, i, tij,self.balls[j].count,self.balls[i].count)
else:
self.PQ.insert(i, j, tij,self.balls[i].count, self.balls[j].count)
return
#draw will draw the borders and all balls within self.balls
def draw(self):
#Draw walls
self.canvas.create_line((self.min_x, self.min_y), (self.min_x, self.max_y), fill = "red")
self.canvas.create_line((self.min_x, self.min_y), (self.max_x, self.min_y), fill = "red")
self.canvas.create_line((self.min_x, self.max_y), (self.max_x, self.max_y), fill = "red")
self.canvas.create_line((self.max_x, self.min_y), (self.max_x, self.max_y), fill = "red")
#Draw balls
for b in self.balls:
obj = self.canvas.create_oval(b.x - b.radius, b.y - b.radius, b.x + b.radius, b.y + b.radius, outline=b.tk_rgb, fill=b.tk_rgb)
self.ball_handles[b] = obj
self.canvas.update()
#refresh is called to update the state of the simulation
#-each refresh call can be considered one iteration of the simulation
#-all balls will be moved and if there is a collision then it will be computed
def refresh(self):
#get the next collision
i, j, t, num_collisions_i, num_collision_j = self.PQ.get_next()
#gather the current collisions of the ith and jth ball
current_collisions_i = self.balls[i].count
current_collisions_j = self.balls[j].count
#Check the difference in time between the predicted collision time and
#the current time stamp of the simulation
delta = t - self.time
#If the difference is greater than 1, then just move the balls
if delta > 1.0:
# cap delta to 1.0
for bi in self.balls:
bi.move()
self.canvas.move(self.ball_handles[bi], bi.vx, bi.vy)
self.time += 1.0
#Otherwise a collision has occurred
else:
#Move all balls
for bi in self.balls:
bi.move(delta)
self.canvas.move(self.ball_handles[bi], bi.vx*delta, bi.vy*delta)
#increment the simulation time stamp
self.time += delta
#Delete the top element within the Priority Queue
self.PQ.delete()
#if i is -1 then this indicates a collision with a vertical wall
#also this if statement checks if the number of collisions recorded
#when the collision returned by PQ.get_next() is equal to the
#number of collisions within the jth ball
#this acts as a test to check if the collision is still valid
if i == -1 and num_collision_j == current_collisions_j:
#compute what happens from the vertical wall collision
self.balls[j].collide_with_vertical_wall()
#update collision times for the jth ball
self.update_collision_times(j)
#if j is -1 then this indicates a collision a horizontal wall
#while also checking if the number of collisions match
#to see if the collision is valid
elif j == -1 and num_collisions_i == current_collisions_i:
#compute what happens from the horizontal wall collision
self.balls[i].collide_with_horizontal_wall()
#update collision times for the ith ball
self.update_collision_times(i)
#Otherwise i and j are not equal to -1 indicating that the collision is between two balls
#check if no collisions have occurred between both balls before the collision returned from PQ.get_next
#if true then this means that the collision is still valid and must be executed
elif num_collision_j == current_collisions_j and num_collisions_i == current_collisions_i:
#Execute collision across the ith and jth ball
self.balls[i].collide_with_ball(self.balls[j])
#update collision times for both the ith and jth ball
self.update_collision_times(i)
self.update_collision_times(j)
#update the canvas to draw the new locations of each ball
self.canvas.update()
self.canvas.after(self.refresh_speed, self.refresh) #Calls the function again
示例3: rmap
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
#.........这里部分代码省略.........
time.sleep(self.sleep)
def start(self,fun):
self.solve_task = fun
self._tk.mainloop()
##Робот
def pause(self,t=1):
"""Приостановка выполнения программы. Пауза в секундах.
#-------------------
r.pause() # пауза в одну секунду
#-------------------
r.pause(2) # пауза две секунды
#-------------------
"""
time.sleep(t)
def left(self, a = 1):
"""Шаг влево
#-------------------
r.left()
#-------------------
r.lt()
#-------------------
r.lt(3)
#-------------------
"""
if a == 1:
if self.freeLeft():
self._c -= 1
self._canvas.move(self._robot,-self._size*a,0)
self._update()
else:
self._stop()
else :
for z in range(0,a):
self.left()
def right(self, a = 1):
""" Шаг вправо
#-------------------
r.right()
#-------------------
r.rt()
#-------------------
r.rt(5)
#-------------------
"""
if a == 1:
if self.freeRight():
self._c += 1
self._canvas.move(self._robot,self._size*a,0)
self._update()
else:
self._stop()
else :
for z in range(0,a):
self.right()
def up(self, a = 1):
"""Шаг вверх
#-------------------
示例4: __init__
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
#.........这里部分代码省略.........
vx = rand.random_sample()
vy = rand.random_sample()
mass = rand.random_sample()
new_ball = Ball(radius, x, y, vx, vy, mass)
if not new_ball.check_overlap(self.balls):
self.balls.append(new_ball)
break
def draw(self):
# Draw walls
self.canvas.create_line((self.min_x, self.min_y), (self.min_x, self.max_y), fill="red")
self.canvas.create_line((self.min_x, self.min_y), (self.max_x, self.min_y), fill="red")
self.canvas.create_line((self.min_x, self.max_y), (self.max_x, self.max_y), fill="red")
self.canvas.create_line((self.max_x, self.min_y), (self.max_x, self.max_y), fill="red")
# Draw balls
for b in self.balls:
obj = self.canvas.create_oval(b.x - b.radius, b.y - b.radius, b.x + b.radius, b.y + b.radius)
self.ball_handles[b] = obj
self.canvas.update()
def next_wall_collision_idx(self):
collided = []
for i in np.arange(self.num_balls):
if self.wall_collision_times[i] <= self.time:
collided.append(i)
return collided
def next_ball_collision_idx(self):
min_i = 0
min_j = 0
collided = []
# min_tij = float('inf')
for i in np.arange(self.num_balls):
for j in np.arange(i, self.num_balls):
tij = self.ball_collision_times[i][j]
if tij <= self.time:
collided.append((i, j))
return collided
# CODE YOU NEED TO IMPLEMENT
def init_wall_collision_times(self):
for i in np.arange(self.num_balls):
self.wall_collision_times[i] = self.balls[i].compute_wall_collision_time(
self, self.min_x, self.max_x, self.min_y, self.max_y
)
# def update_wall_collision_time(self, i):
#
def init_ball_collision_times(self):
for i in np.arange(self.num_balls):
for j in np.arange(self.num_balls):
self.ball_collision_times[i] = self.balls[i].compute_ball_collision_time(self, other)
#
# def update_ball_collision_time(self, i):
# Do not update this
def refresh(self):
wall_i = self.next_wall_collision_idx()
ball_i = self.next_ball_collision_idx()
# print wall_i, ball_i
for i in wall_i:
bi = self.balls[i]
old_x = bi.x
old_y = bi.y
bi.collide_with_wall(self.min_x, self.max_x, self.min_y, self.max_y)
self.canvas.move(self.ball_handles[bi], bi.x - old_x, bi.y - old_y)
for (i, j) in ball_i:
bi = self.balls[i]
bj = self.balls[j]
bi.collide_with_ball(bj)
collided = wall_i
for (i, j) in ball_i:
collided.append(i)
collided.append(j)
collided = set(collided)
# print collided
for i in collided:
self.update_ball_collision_time(i)
self.update_wall_collision_time(i)
not_collided = set(np.arange(self.num_balls)) - collided
for i in not_collided:
bi = self.balls[i]
old_x = bi.x
old_y = bi.y
bi.move()
self.canvas.move(self.ball_handles[bi], bi.x - old_x, bi.y - old_y)
self.time += 1
self.canvas.update()
self.canvas.after(self.refresh_speed, self.refresh) # Calls the function again
示例5: Scene
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [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)
示例6: TKinterDisplay
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
#.........这里部分代码省略.........
x2angle = math.radians(270)
a1 = (id1tuple[2] - id1tuple[0]) / 2
b1 = (id1tuple[3] - id1tuple[1]) / 2
a2 = (id2tuple[2] - id2tuple[0]) / 2
b2 = (id2tuple[3] - id2tuple[1]) / 2
r1 = a1 * b1 / (math.sqrt(((a1 * a1) * (math.pow(math.sin(x1angle), 2))) + ((b1 * b1) * math.pow(math.cos(x1angle), 2))))
r2 = a2 * b2 / (math.sqrt(((a2 * a2) * (math.pow(math.sin(x2angle), 2))) + ((b2 * b2) * math.pow(math.cos(x2angle), 2))))
x1 = x1 + ((r1 / hyp) * (x2 - x1))
y1 = y1 + ((r1 / hyp) * (y2 - y1))
#x2 = x2 + ((r2 / hyp) * (x1 - x2))
#y2 = y2 - ((r2 / hyp) * (y1 - y2))
return self.__drawLine(x1, y1, x2, y2, tags, colour)
@abstractmethod
def renderTextInId(self, tagTocentreOn, tagsToAddTo, content, funcContent):
id1tuple = self.__getCoords(tagTocentreOn)
x1 = id1tuple[0] + ((id1tuple[2] - id1tuple[0]) / 2)
y1 = id1tuple[1] + ((id1tuple[3] - id1tuple[1]) / 2)
txt = self.__renderText(x1, y1, (id1tuple[2] - id1tuple[0]), content, tagsToAddTo)
def handler(event, self=self, content=funcContent):
return self.__eventOnClick(event, content)
self.localCanvas.tag_bind(txt, "<ButtonRelease-1>", handler)
return txt
@abstractmethod
def move(self, tag, xamount, yamount):
self.localCanvas.move(tag, xamount, yamount)
@abstractmethod
def runDisplay(self):
self.localCanvas.mainloop()
def __hideId(self, objectId):
self.localCanvas.itemconfigure(objectId, state="hidden")
pass
def __showId(self, objectId):
self.localCanvas.itemconfigure(objectId, state="normal")
pass
def __sampleDraw(self):
self.localCanvas.create_oval(0, 0, 0, 0, width=0)
def __renderText(self, x, y, width, content, tag):
val = self.localCanvas.create_text(x, y, width=width, text=content, tags=tag, justify="center", font="Helvetica 8 bold", anchor="center")
self.localCanvas.tag_raise(val)
return val
def __drawLine(self, x1, y1, x2, y2, tags=None, colour="black"):
line = self.localCanvas.create_line(x1, y1, x2, y2, tags=tags, width=self.lineThickness, arrow="first", arrowshape=(16,20,6),fill=colour, smooth=True)
self.localCanvas.tag_lower(line)
return # line
def __remove(self, num):
self.localCanvas.delete(num)
def __getCoords(self, ident):
示例7: move
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
def move(self, i, j, canvas: Canvas):
diff_x = (i - self.i) * DD
diff_y = (j - self.j) * DD
self.i = i
self.j = j
canvas.move(self.id, diff_x, diff_y)
示例8: Board
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import move [as 别名]
class Board():
BOX_SIZE = 50
WIDTH = 500
HEIGHT = 700
def __init__(self, root):
self.canvas = Canvas(
root,
width=Board.WIDTH,
height=Board.HEIGHT)
self.canvas.pack()
def create_rectangle(self):
return self.canvas.create_rectangle(100, 0, Board.BOX_SIZE, Board.BOX_SIZE, fill="blue")
def fall(self, box):
if self.can_move(box, 0, 1):
self.canvas.move(box, 0, Board.BOX_SIZE)
def can_move(self, box, x, y):
x = x * Board.BOX_SIZE
y = y * Board.BOX_SIZE
coords = self.canvas.coords(box)
if coords[0] + x < 0: return False
if coords[2] + x > Board.WIDTH: return False
if coords[3] + y > Board.HEIGHT: return False
if set(self.canvas.find_overlapping(
(coords[0] + coords[2]) / 2 + x,
(coords[1] + coords[3]) / 2 + y,
(coords[0] + coords[2]) / 2 + x,
(coords[1] + coords[3]) / 2 + y
)):
return False
return True