当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.coords方法代码示例

本文整理汇总了Python中tkinter.Canvas.coords方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.coords方法的具体用法?Python Canvas.coords怎么用?Python Canvas.coords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.Canvas的用法示例。


在下文中一共展示了Canvas.coords方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Schedules

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [as 别名]
def Schedules(profBook, profBook0):

	from tkinter import Tk
	from tkinter import Canvas
	import os

	mod = 1
	try: profBook[-1]
	except: mod = 0
	for professor in (range(len(profBook)-mod)):
		master = Tk()

		w=1240
		h=1754
		x=86
		y=86

		c = Canvas(master, width=1240, height=1754)
		c.pack()
	
		# Initial solution
	
		c.create_text(w/2, y, font=("Ubuntu","16", "bold"), text="Professor "+str(professor)+" schedule in initial solution")

		c.create_rectangle(x, y+30, x+124, y+48, fill="#fff", tags=("00n","init")) # Blank rectangle

		c.create_rectangle(x, y+48, x+124, y+120, fill="#fff", tags=("01n","init"))     # 
		xp = (c.coords("01n")[0]+c.coords("01n")[2])/2                                   # 8:00 am 
		yp = (c.coords("01n")[1]+c.coords("01n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="8:00 am - 10:00 am")          # 

		c.create_rectangle(x, y+120, x+124, y+192, fill="#fff", tags=("02n","init"))    # 
		xp = (c.coords("02n")[0]+c.coords("02n")[2])/2                                   # 10:00 am 
		yp = (c.coords("02n")[1]+c.coords("02n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="10:00 am - 12:00 pm")         # 

		c.create_rectangle(x, y+192, x+124, y+228, fill="#fff", tags=("03n","init"))    # 
		xp = (c.coords("03n")[0]+c.coords("03n")[2])/2                                   # 12:00 pm 
		yp = (c.coords("03n")[1]+c.coords("03n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="12:00 pm - 2:00 pm")          #

		c.create_rectangle(x, y+228, x+124, y+300, fill="#fff", tags=("04n","init"))    # 
		xp = (c.coords("04n")[0]+c.coords("04n")[2])/2                                   # 2:00 pm 
		yp = (c.coords("04n")[1]+c.coords("04n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="2:00 pm - 4:00 pm")           #

		c.create_rectangle(x, y+300, x+124, y+372, fill="#fff", tags=("05n","init"))    # 
		xp = (c.coords("05n")[0]+c.coords("05n")[2])/2                                   # 4:00 pm 
		yp = (c.coords("05n")[1]+c.coords("05n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="4:00 pm - 6:00 pm")           #

		c.create_rectangle(x, y+372, x+124, y+408, fill="#fff", tags=("06n","init"))    # 
		xp = (c.coords("06n")[0]+c.coords("06n")[2])/2                                   # 6:00 pm 
		yp = (c.coords("06n")[1]+c.coords("06n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="6:00 pm - 7:00 pm")           #

		c.create_rectangle(x, y+408, x+124, y+480, fill="#fff", tags=("07n","init"))    # 
		xp = (c.coords("07n")[0]+c.coords("07n")[2])/2                                   # 7:00 pm 
		yp = (c.coords("07n")[1]+c.coords("07n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="7:00 pm - 9:00 pm")           #

		c.create_rectangle(x, y+480, x+124, y+552, fill="#fff", tags=("08n","init"))    # 
		xp = (c.coords("08n")[0]+c.coords("08n")[2])/2                                   # 9:00 pm 
		yp = (c.coords("08n")[1]+c.coords("08n")[3])/2                                   # rectangle
		c.create_text(xp, yp, font=("Arial","12"), text="9:00 pm - 11:00 pm")          #

		week = ['Monday','Tuesday','Wednesday', 'Thursday', 'Friday']
		for i in range(5):
			c.create_rectangle(x+124+i*186, y+30, x+310+i*186, y+48, fill="#fff")
			c.create_rectangle(x+124+i*186, y+48, x+310+i*186, y+120, fill="#fff", tags=("00,0"+str(2*i),"init"))
			c.create_rectangle(x+124+i*186, y+120, x+310+i*186, y+192, fill="#fff", tags=("00,0"+str(2*i+1),"init"))
			c.create_rectangle(x+124+i*186, y+192, x+310+i*186, y+228, fill="#fff")
			c.create_rectangle(x+124+i*186, y+228, x+310+i*186, y+300, fill="#fff", tags=("01,0"+str(2*i),"init"))
			c.create_rectangle(x+124+i*186, y+300, x+310+i*186, y+372, fill="#fff", tags=("01,0"+str(2*i+1),"init"))
			c.create_rectangle(x+124+i*186, y+372, x+310+i*186, y+408, fill="#fff")
			c.create_rectangle(x+124+i*186, y+408, x+310+i*186, y+480, fill="#fff", tags=("02,0"+str(2*i),"init"))
			c.create_rectangle(x+124+i*186, y+480, x+310+i*186, y+552, fill="#fff", tags=("02,0"+str(2*i+1),"init"))
			c.create_text(x+217+i*186, y+39, font=("Arial","12"), text=week[i])

		halfSlots = []
		for i in range(len(profBook0[professor])):
			for j in range(5,len(profBook0[professor][i])):
			
				sbj = profBook0[professor][i][0]
				slot = profBook0[professor][i][j]
			
				if(j+1==len(profBook0[professor][i]) and profBook0[professor][i][2]%2==1):
				
					coord = c.coords("0"+str(profBook0[professor][i][1])+",0"+str(slot))
					coord = [int(i) for i in coord]
					if("0"+str(profBook0[professor][i][1])+",0"+str(slot) in halfSlots):
						c.create_rectangle((coord[0]+coord[2])/2, coord[1], coord[2], coord[3], fill="#ccc")
						c.create_text((coord[0]+3*coord[2])/4,(coord[1]+coord[3])/2, font=("Ubuntu","15"), justify='center', text="Subject "+str(sbj))
					else:
						c.create_rectangle(coord[0], coord[1], (coord[0]+coord[2])/2, coord[3], fill="#ccc")
						halfSlots.append("0"+str(profBook0[professor][i][1])+",0"+str(slot))
						c.create_text((3*coord[0]+coord[2])/4,(coord[1]+coord[3])/2, font=("Ubuntu","15"), justify='center', text="Subject "+str(sbj))
				else:
			
					coord = c.coords("0"+str(profBook0[professor][i][1])+",0"+str(slot))
#.........这里部分代码省略.........
开发者ID:allrod5,项目名称:optimization-algorithms,代码行数:103,代码来源:report.py

示例2: Scene

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [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)
开发者ID:poussin87,项目名称:haptiq,代码行数:80,代码来源:view.py

示例3: rmap

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [as 别名]

#.........这里部分代码省略.........
        """ Шаг вниз
#-------------------
r.down()
#-------------------
r.dn()
#-------------------
r.dn(4)
#-------------------
"""
        if a == 1:
            if self.freeDown():
                self._r += 1
                self._canvas.move(self._robot,0,self._size*a)
                self._update()
            else:
                self._stop()
        else :
            for z in range(0,a):
                self.down()
                
    def jumpTo(self,coord=(1,1)):
        """Прыжок в клетку с указанными координами. Через стены.
#-------------------
r.jumpTo((2,3)) # Робот окажется в третьем столбце второй строки
#-------------------
"""

        r = coord[0]
        c = coord[1]
        if ( 0 < r < self._nc) and (0 < c < self._nc):
            self._r = r
            self._c = c
            size = self._size
            self._canvas.coords(self._robot, c*size+4,r*size+4, c*size+size-4,r*size+size-4)
            self._canvas.lift(self._robot)
            self._update()
        else:
            print("Попытка переместиться за пределы поля. Отказано.")

    def paint (self, color = 'green'):
        """ Закрасить текущую клетку выбранным цветом. Если цвет не указан, то зеленым
#-------------------
r.paint() # Закрасит текущую клетку зеленым цветом
#-------------------
r.pt() # Закрасит текущую клетку зеленым цветом
#-------------------
r.pt('red') # Закрасит текущую клетку красным цветом
#-------------------
r.pt(r.randcolor()) # Закрасит текущую клетку случайным цветом
#-------------------
r.pt(r.label()) # Закрасит текущую клетку цветом метки в этой клетке
#-------------------
"""
        d = self._d+1
        self._field[self._r][self._c].color = color

        x1 = self._size*(self._c)
        x2 = self._size*(self._c+1)
        y1 = self._size*(self._r)
        y2 = self._size*(self._r+1)
        self._canvas.delete(self._field[self._r][self._c].v.color)
        self._field[self._r][self._c].v.color = self._canvas.create_rectangle(x1+d,y1+d,x2-d,y2-d, width = 0, fill = color)
        self._canvas.lift(self._field[self._r][self._c].v.text)
        self._canvas.lift(self._robot)
        self._canvas.lift(self._park)
        self._update()
开发者ID:Katya1518,项目名称:Ogurtsova,代码行数:70,代码来源:robot.py

示例4: TKinterDisplay

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [as 别名]

#.........这里部分代码省略.........
    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):
        return self.localCanvas.coords(ident)
    
    def __eventOnFrameConfigure(self, event):
        '''Reset the scroll region to encompass the inner frame'''
        assert self.localCanvas
        coord_tuple = self.localCanvas.bbox("all")
        if not coord_tuple:
            logging.error("Frame reconfigure error on coordinate acquire.")
        else:
            reconWidth = coord_tuple[2] - coord_tuple[0]
            reconHeight = coord_tuple[3] - coord_tuple[1]
            self.localCanvas.configure(width=reconWidth)
            self.localCanvas.configure(height=reconHeight)
            self.localCanvas.configure(scrollregion=self.localCanvas.bbox("all"))
            self.localCanvas.update_idletasks()
    
    def __eventOnClick(self, event, content):
        self.__createWindowOnId(self.localCanvas.find_withtag(CURRENT), content)
        
    def __createWindowOnId(self, itemId, content):
        if self.currentlyRenderedWindow != None:
            self.currentlyRenderedWindow()
        # self.__remove(self.currentlyRenderedWindow)
        idtuple = self.localCanvas.coords(itemId)
        if idtuple:
            x = idtuple[0]
            y = idtuple[1]
            frm = Frame(self.localCanvas)
            frm.grid(row=0, column=0)
            canv = Canvas(frm)            
            
            vscroll = Scrollbar(frm, orient="vertical", command=canv.yview)
            vscroll.grid(row=0, column=1, sticky=N + S)
            
            canv.grid(row=0, column=0)
            
            canv["yscrollcommand"] = vscroll.set
            aframe = Frame(canv)
            aframe.grid(row=0, column=0)
            Label(aframe, text=content, anchor="center", background="#CCFFCC", borderwidth=6, relief="ridge", justify="left").grid(row=1, column=0)
            canvWindow = canv.create_window(x, y, window=aframe)
            canv.coords(canvWindow, x, y)
            self.localCanvas.update_idletasks()
            canv["scrollregion"] = canv.bbox("all")
            
            def destroyAll():
                self.__remove(canvWindow)
                canv.destroy()
                aframe.destroy()
                vscroll.destroy()
                frm.destroy()
                
            self.currentlyRenderedWindow = destroyAll 
            Button(frm, text="Close", command=lambda :  destroyAll()).grid(row=2, column=0)
开发者ID:Capgemini,项目名称:PyPomVisualiser,代码行数:104,代码来源:TKinterDisplay.py

示例5: __init__

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [as 别名]
class World:
    def __init__(self, tk):
        self._debug=False
        self.running=True
        self.playing=False
        self.drawFPS=False
        self.tk = tk
        self.tk.protocol("WM_DELETE_WINDOW", self.endWorld)
        self.canvas = Canvas(tk, width=640, height=480, bg="white")
        self.canvas.pack()
        self.depth = 100
        self.lastUpdateTime=0
        self.entities = []
        self.collisions = []
        #self.initBindings2D()
        self.initBindings3D()

    def initBindings3D(self):
        self.canvas.bind("<Button-1>", self.createLine)
        self.canvas.bind("<Button-3>", self.togglePlaying)
        self.canvas.bind("<B1-Motion>", self.moveLine)
        self.canvas.bind("<B1-ButtonRelease>", self.createSphere)

    def initBindings2D(self):
        self.canvas.bind("<Button-1>", self.createLine)
        self.canvas.bind("<B1-Motion>", self.moveLine)
        self.canvas.bind("<B1-ButtonRelease>", self.createCircle)
        self.canvas.bind("<Button-3>", lambda x: self.togglePlaying())
        self.tk.bind("<space>", lambda x: self.togglePlaying())
        self.tk.bind("<BackSpace>", lambda x: self.reverse())
        self.tk.bind("r", lambda x: self.reset())
        self.tk.bind("c", lambda x: self.recalculateFutureCollisions())
        self.tk.bind("d", lambda x: self.toggleDebug())

    def createLine(self, event):        
        self.currentLine = self.canvas.create_line(event.x, event.y, event.x, event.y)

    def moveLine(self, event):
        coords = self.canvas.coords(self.currentLine)
        self.canvas.coords(self.currentLine, coords[0], coords[1], event.x, event.y)

    def createSphere(self, event):
        coords = self.canvas.coords(self.currentLine)
        x1 = coords[0]
        y1 = coords[1]
        x2 = event.x
        y2 = event.y
        if x1==x2 and y1==y2:
            x1-=1
        # INFO : Räknar ut avståndet med hälp av Pythagoras sats
        distance = math.sqrt(math.pow(x1-x2,2)+math.pow(y1-y2,2))
        # INFO : Räknar ut vinkeln med hjälp av arccos (samt avstådent ovan).
        angleInRadians = math.acos((x2-x1)/distance)
        angleInDegrees = math.degrees(angleInRadians)
        if(y1 > y2):
            angleInDegrees += (180-angleInDegrees)*2        
        #radius = random.randint(10,30)
        sphere = Sphere(x1, y1, angleInDegrees, self.canvas, velocity=distance , radius=20) )
        self.entities.append(sphere)
        self.canvas.delete(self.currentLine)
        self.checkFutureCollisions3D(sphere)
        
    def createCircle(self, event):
        coords = self.canvas.coords(self.currentLine)
        x1 = coords[0]
        y1 = coords[1]
        x2 = event.x
        y2 = event.y
        if(x1==x2 and y1==y2):
            x1-=1
        distance = math.sqrt(math.pow(x1-x2,2)+math.pow(y1-y2,2))
        velocity = distance
        angleInRadians = math.acos((x2-x1)/distance)        
        angleInDegrees = math.degrees(angleInRadians)
        if(y1 > y2):
            angleInDegrees += (180-angleInDegrees)*2        
        radius = random.randint(10,30)
        circleId = self.canvas.create_oval(x1-radius,y1-radius,x1+radius,y1+radius, tags="circle", fill="#"+str(random.randint(100,999)))
        circle = Circle2D(circleId, self.canvas, angleInDegrees, radius,
                velocity)
        self.entities.append(circle)
        self.canvas.delete(self.currentLine)
        self.checkFutureCollisions2D(circle)
开发者ID:zarac,项目名称:tgspu-coolgang,代码行数:85,代码来源:Coolacoolgangetsapp.py

示例6: TkLEDTableMixin

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [as 别名]
class TkLEDTableMixin(object):

    BACKGROUND_COLOR = "black"
    BORDER_COLOR = "gray"
    PIXEL_ORDER_COLOR = "white"
    PIXEL_WIDTH = 30
    PIXEL_HEIGHT = 30
    PIXEL_BORDER = 1
    
    def __init__(self, *args, **kw):
        self._canvas = Canvas(self, width = 0, height = 0)
        self._canvas.pack()
        self._pixels = []
        self._saved_pixels = []
        self._pixel_order = []
        self._pixel_width = self.PIXEL_WIDTH
        self._pixel_height = self.PIXEL_HEIGHT
        self._pixel_border = self.PIXEL_BORDER
        self._height = self._width = 0

    # initial configuration

    @property
    def width(self):
        return self._width

    @width.setter
    def width(self, value):
        self.dimensions = value, self.height
        
    @property
    def height(self):
        return self._height

    @height.setter
    def height(self, value):
        self.dimensions = self.width, value

    @property
    def dimensions(self):
        return self._width, self._height

    @dimensions.setter
    def dimensions(self, value):
        width, height = value
        self._remove_all_pixels()
        self._width, self._height = width, height
        self._create_pixels()

    # utility methods

    def _create_pixels(self):
        assert not self._pixels
        for y in range(self.height):
            pixels = []
            self._pixels.append(pixels)
            for x in range(self.width):
                pixel = self._canvas.create_rectangle(0,0,1,1)
                pixels.append(pixel)
        self._update_configuration()
        for y, row in enumerate(self._saved_pixels[:self.height]):
            for x, color in enumerate(row[:self.width]):
                self.set_pixel_color(x, y, color)

    def _remove_all_pixels(self):
        self._saved_pixels = [[self.get_pixel_color(x, y) for x in range(self.width)] for y in range(self.height)]
        for pixel in self._all_pixels:
            self._canvas.delete(pixel)
        self._pixels = []
        self._remove_pixel_order()

    def _remove_pixel_order(self):
        for line in self._pixel_order:
            self._canvas.delete(line)
        self._pixel_order = []

    @property
    def _all_pixels(self):
        return chain.from_iterable(self._pixels)

    def _update_configuration(self):
        for y, row in enumerate(self._pixels):
            for x, pixel in enumerate(row):
                x_cor = x * self.pixel_width
                y_cor = y * self.pixel_height
                self._canvas.coords(pixel, x_cor, y_cor,
                                           x_cor + self.pixel_width,
                                           y_cor + self.pixel_height)
                self._canvas.itemconfigure(pixel, outline = self.BORDER_COLOR,
                                                  fill = self.BACKGROUND_COLOR,
                                                  width = self.pixel_border)
        self._canvas.configure(width = self.width * self.pixel_width,
                               height = self.height * self.pixel_height)
    # pixel configuration

    @property
    def pixel_width(self):
        return self._pixel_width

    @pixel_width.setter
#.........这里部分代码省略.........
开发者ID:niccokunzmann,项目名称:ledtable,代码行数:103,代码来源:tkLEDTable.py

示例7: __createWindowOnId

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [as 别名]
 def __createWindowOnId(self, itemId, content):
     if self.currentlyRenderedWindow != None:
         self.currentlyRenderedWindow()
     # self.__remove(self.currentlyRenderedWindow)
     idtuple = self.localCanvas.coords(itemId)
     if idtuple:
         x = idtuple[0]
         y = idtuple[1]
         frm = Frame(self.localCanvas)
         frm.grid(row=0, column=0)
         canv = Canvas(frm)            
         
         vscroll = Scrollbar(frm, orient="vertical", command=canv.yview)
         vscroll.grid(row=0, column=1, sticky=N + S)
         
         canv.grid(row=0, column=0)
         
         canv["yscrollcommand"] = vscroll.set
         aframe = Frame(canv)
         aframe.grid(row=0, column=0)
         Label(aframe, text=content, anchor="center", background="#CCFFCC", borderwidth=6, relief="ridge", justify="left").grid(row=1, column=0)
         canvWindow = canv.create_window(x, y, window=aframe)
         canv.coords(canvWindow, x, y)
         self.localCanvas.update_idletasks()
         canv["scrollregion"] = canv.bbox("all")
         
         def destroyAll():
             self.__remove(canvWindow)
             canv.destroy()
             aframe.destroy()
             vscroll.destroy()
             frm.destroy()
             
         self.currentlyRenderedWindow = destroyAll 
         Button(frm, text="Close", command=lambda :  destroyAll()).grid(row=2, column=0)
开发者ID:Capgemini,项目名称:PyPomVisualiser,代码行数:37,代码来源:TKinterDisplay.py

示例8: Board

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import coords [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
开发者ID:pritz2,项目名称:Tketris,代码行数:37,代码来源:Tketris.py


注:本文中的tkinter.Canvas.coords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。