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


Python Canvas.tag_lower方法代码示例

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


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

示例1: Window

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

#.........这里部分代码省略.........
        #Set up the board and piece roster
        squareSize = min(maxBoardWidth/puzzle.cols, maxBoardHeight/puzzle.rows)
        self.blockWidth = squareSize
        self.blockHeight = squareSize
        self.boardWidth = self.blockWidth*puzzle.cols
        self.boardHeight = self.blockHeight*puzzle.rows

        self.rosterStartX = boardStartX + self.boardWidth + extRosterPadding

        rosterX = self.rosterStartX
        rosterY = boardStartY + intRosterPadding
        maxHeight = 0

        #Start creating pieces, filling roster as we go
        for piece in puzzle.universe:
            label = piece.getLabel()
            if rosterX + intRosterPadding + piece.cols*self.blockWidth + intRosterPadding - self.rosterStartX <= rosterWidth:
                self.pieces.append(drawnBlock(self.canvas,piece,rosterX+intRosterPadding,rosterY,label=label, colour = colourDict[label], boxSize = self.blockWidth))
                rosterX += intRosterPadding + piece.cols*self.blockWidth
                if piece.rows*self.blockHeight>maxHeight:
                    maxHeight = piece.rows*self.blockHeight
            else:
                rosterX = self.rosterStartX
                rosterY += maxHeight + intRosterPadding
                maxHeight = piece.rows*self.blockHeight
                self.pieces.append(drawnBlock(self.canvas,piece,rosterX+intRosterPadding,rosterY,label=label, colour = colourDict[label], boxSize = self.blockWidth))
                rosterX += intRosterPadding + piece.cols*self.blockWidth

        #Draw board and roster
        for i in range(1,puzzle.rows):

            tag=self.canvas.create_rectangle(boardStartX+i*self.blockWidth - 1, boardStartY,
                                             boardStartX+i*self.blockWidth + 1, boardStartY+self.boardHeight, fill="#333333",width=0)
            self.canvas.tag_lower(tag)
        for j in range(1,puzzle.cols):
            tag=self.canvas.create_rectangle(boardStartX, boardStartY + j*self.blockHeight - 1,
                                             boardStartX + self.boardWidth, boardStartY+j*self.blockHeight+1, fill="#333333",width=0)
            self.canvas.tag_lower(tag)
        tag=self.canvas.create_rectangle(boardStartX, boardStartY, boardStartX + self.boardWidth, boardStartY + self.boardHeight,fill="white",width=2)
        self.canvas.tag_lower(tag)

        tag = self.canvas.create_rectangle(boardStartX + self.boardWidth + extRosterPadding, boardStartY,
                                  boardStartX + self.boardWidth + extRosterPadding + rosterWidth, rosterY + maxHeight + intRosterPadding, fill="white")
        self.canvas.tag_lower(tag)



    def move(self, move):
        #Puts a piece into (i,j) or sends it home

        piece = self.getPiece(move.tag)
        if move.home:
            piece.setMove(piece.homeX,piece.homeY)
        else:
            x = boardStartX + move.i*self.blockWidth
            y = boardStartY + move.j*self.blockHeight
            piece.setMove(x,y)

    def getPiece(self, tag):
        foundPiece = -1
        for piece in self.pieces:
                if piece.label == tag:
                    foundPiece = piece
                    break
        if foundPiece == -1:
            print("Error: No piece for tag \'"+ str(tag) + "\' found")
开发者ID:j-salazar,项目名称:block-solver,代码行数:70,代码来源:blockgame.py

示例2: prgCanvas

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import tag_lower [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")
开发者ID:sergnov,项目名称:PrgViewer,代码行数:104,代码来源:prgviewer.py

示例3: TKinterDisplay

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import tag_lower [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


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