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


Python Canvas.update_idletasks方法代码示例

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


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

示例1: simpleGui

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import update_idletasks [as 别名]
class simpleGui(tkinter.Tk):
    
    def __init__(self, parent):
        tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialize()
        
    def initialize(self):
        self.grid()
        self.config(bg="white")
        self.geometry("600x500")
        
        self.algo = ACAlgo()
        self.wordFrames=[]
        
        self.path=""
        self.lastCanvasIndex=0
        
        rowLine=0
        
        
        self.entryPath = tkinter.Entry(self, width=75)
        self.entryPath.grid(column=0, row=rowLine,columnspan=3, sticky='NEW')
        self.entryPath.bind("<Return>", self.setPath)
        
        buttonSetPath = tkinter.Button(self, text="Set path", width=21, height=1, command=self.setPath)
        buttonSetPath.grid(column=3, row=rowLine, sticky='EWN')
                
                
                
        rowLine=rowLine+1
        
        self.entry = tkinter.Entry(self, width=75)
        self.entry.grid(column=0, row=rowLine,columnspan=2, sticky='NEWS')
        self.entry.bind("<Return>", self.addWords)

        buttonAddWords = tkinter.Button(self, text="Add words", width=21,height=1, command=self.addWords)
        buttonAddWords.grid(column=3, row=rowLine, sticky='EWNS')
        
        
        
        rowLine=rowLine+1
        self.grid_rowconfigure(rowLine, weight=1)
        self.textBox = tkst.ScrolledText(self, width=20, height=10)
        self.textBox.grid(column=0, row=rowLine, columnspan=3, sticky='NWES')
        
        self.textBox.config(state=DISABLED)
        
       
        self.canvas= Canvas(master=self,width=150)
        self.vscroll = Scrollbar(self)
        
        self.vscroll.config(command=self.canvas.yview)
        self.canvas.config(yscrollcommand=self.vscroll.set) 

        self.canvas.grid( row=rowLine, column=3,  sticky='NES')
        self.vscroll.grid(padx=1,  pady=1, row=rowLine, column=4, sticky='NEWS')
        
        
        
        rowLine=rowLine+1
                
        buttonClearHighlight = tkinter.Button(self, text="Clear highlight", width=20, command=self.removeHighlightsBtn)
        buttonClearHighlight.grid(column=0, row=rowLine, sticky="WS")


        buttonDeleteWords = tkinter.Button(self, text="Delete words", width=20, command=self.resetAll)
        buttonDeleteWords.grid(column=3, row=rowLine, sticky="ES")
        
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

    def setPath(self):
        try:
            open(self.entryPath.get())
        except:
            return
        self.path=self.entryPath.get()
        self.textBox.config(state=NORMAL)
        self.textBox.insert(tkinter.INSERT, open(self.path).read())
        self.textBox.config(state=DISABLED)
        
    def removeHighlights(self):
        for wordFrame in self.wordFrames:
            wordFrame.removeHighLight()

    def removeHighlightsBtn(self, entry=""):
        for wordFrame in self.wordFrames:
            wordFrame.removeHighLight()
        
        self.update_idletasks()
            
    def resetAll(self, entry=""):
        self.removeHighlights()
        self.algo.resetTree()
        self.lastCanvasIndex=0;
        self.wordFrames=[]
        self.canvas.delete("all")
        self.update_idletasks()
        
#.........这里部分代码省略.........
开发者ID:adrianobacac,项目名称:seminarFinalno,代码行数:103,代码来源:gui.py

示例2: TKinterDisplay

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