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


Python Canvas.tag_raise方法代码示例

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


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

示例1: View

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import tag_raise [as 别名]
class View():
    def __init__(self, root, controller):
        self.__controller = controller
        root.wm_title("Bomber")
        self.__windowsystem = root.call('tk', 'windowingsystem')
        self.__frame = root
        self.__canvas = Canvas(self.__frame, width=int(CANVAS_WIDTH),
                               height=int(CANVAS_HEIGHT), bg="white")
        self.__canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
        self.__init_fonts()
        self.__init_arena()
        self.__init_score()
        self.__block_views = [] # type: List[BlockView]
        self.__blockfield_view = BlockfieldView()
        self.__messages = []

    def __init_fonts(self):
        self.bigfont = font.nametofont("TkDefaultFont")
        self.bigfont.configure(size=int(48))
        self.scorefont = font.nametofont("TkDefaultFont")
        self.scorefont.configure(size=int(20))


    def __init_score(self):
        self.score_text = self.__canvas.create_text(5, 5, anchor="nw")
        self.__canvas.itemconfig(self.score_text, text="Score:", font=self.scorefont)

    def __init_arena(self):
        self.__canvas.create_rectangle(LEFT_OFFSET, TOP_OFFSET,
                                       LEFT_OFFSET + MAXCOL*GRID_SIZE,
                                       TOP_OFFSET+MAXROW*GRID_SIZE, fill="black")

        nextblocktext = self.__canvas.create_text(GRID_SIZE,
                                                  TOP_OFFSET + GRID_SIZE * 4, anchor="nw")
        self.__canvas.itemconfigure(nextblocktext, text="Next:",
                                    font=self.bigfont, fill="black")

        self.__autoplay_text = self.__canvas.create_text(LEFT_OFFSET + GRID_SIZE * 5,
                                                         TOP_OFFSET - GRID_SIZE, anchor="c")
        self.__canvas.itemconfigure(self.__autoplay_text, text="Play mode",
                                    font=self.bigfont, fill="black")

    def register_block(self, block):
        block_view = BlockView(block)
        self.__block_views.append(block_view)

    def unregister_block(self, block):
        for block_view in self.__block_views:
            if block_view.block is block:
                block_view.erase(self.__canvas)
                self.__block_views.remove(block_view)

    def update_blockfield(self, blockfield):
        self.__blockfield_view.redraw(self.__canvas, blockfield)

    def display_score(self):
        self.__canvas.itemconfig(self.score_text, text="Score: " + str(self.__controller.score),
                                 font=self.scorefont)

    def show_autoplay(self, autoplay):
        if autoplay:
            self.__canvas.itemconfig(self.__autoplay_text, text="Auto-play mode",
                                     font=self.scorefont, fill="black")
        else:
            self.__canvas.itemconfig(self.__autoplay_text, text="Manual mode",
                                     font=self.scorefont, fill="black")

    def game_over(self):
        text1 = self.__canvas.create_text(LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
                                          CANVAS_HEIGHT/2, anchor="c")
        text2 = self.__canvas.create_text(LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
                                          CANVAS_HEIGHT/2 + 100, anchor="c")
        text1_shadow = self.__canvas.create_text(2 + LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
                                                 2 + CANVAS_HEIGHT/2, anchor="c")
        text2_shadow = self.__canvas.create_text(2 + LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
                                                 2 + CANVAS_HEIGHT/2 + 100, anchor="c")
        self.__messages.append(text1)
        self.__messages.append(text2)
        self.__messages.append(text1_shadow)
        self.__messages.append(text2_shadow)
        self.__canvas.itemconfig(text1, text="GAME OVER!",
                                 font=self.bigfont, fill="white")
        self.__canvas.itemconfig(text2, text="Press r to play again.",
                                 font=self.scorefont, fill="white")
        self.__canvas.itemconfig(text1_shadow, text="GAME OVER!",
                                 font=self.bigfont, fill="black")
        self.__canvas.itemconfig(text2_shadow, text="Press r to play again.",
                                 font=self.scorefont, fill="black")
        self.__canvas.tag_raise(text1)
        self.__canvas.tag_raise(text2)

    def clear_messages(self):
        for txt in self.__messages:
            self.__canvas.delete(txt)
        self.__messages.clear()

    def update(self):
        for block_view in self.__block_views:
            block_view.redraw(self.__canvas)
        self.display_score()
开发者ID:magetron,项目名称:ENGF0002,代码行数:102,代码来源:te_view.py

示例2: TKinterDisplay

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import tag_raise [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_raise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。