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


Python Frame.update方法代码示例

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


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

示例1: MapFrame

# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import update [as 别名]
class MapFrame(Frame):
    def __init__(self,parent,mapping,active=False,copy=None,*args,**kwargs):
        Frame.__init__(self,parent,*args,**kwargs)
        self.active = active
        self.mapping = mapping
        self.mapVar = StringVar(self)
        self.mapVar.trace("w",lambda a,b,c:self.copyMapping())
        self.copy = copy
        self.subsetframes = {}

        if self.mapping.isEmpty():
            title = "No elements to map yet"
            message = "Please add some elements before mapping."
            tkMessageBox.showinfo(title,message,parent=self.master)
            return

        self.mapButton = Button(self,text="Map",command=self.popUp)
        self.mapButton.grid()
        self.grid()
    
    def formatKey(self,key):
        if len(key) > 60:
            key = key[:21] + '...' + key[-19:]
        return key
    
    def popUp(self):
        self.pop = Toplevel()
        self.pop.title("Name mapping")
        self.frame = Frame(self.pop,padx=5,pady=5)
        self.listFrame = ScrolledFrame(self.frame)
        self.similars = self.getSimilarItems()
        
        row = 0
        Label(self.frame,text="From: ").grid(row=row,column=0,sticky="W")
        Label(self.frame,text="To: ").grid(row=row,column=2,sticky="W")

        self.buildList()
        self.listFrame.grid(sticky='W', row=1,column=0,columnspan=4)

        Button(self.frame,text="Save",command=self.onSave)\
               .grid(sticky='W',row=2,column=0)

        Label(self.frame,text="Copy From: ").grid(sticky='W',row=2,column=1)
        OptionMenu(self.frame,self.mapVar,*self.similars.keys()).grid(sticky='W',row=2,column=2)

        self.frame.pack()
        self.frame.update()
        
    def getSimilarItems(self):
        ret = {"":None}
        if self.copy:
            ret = dict([(str(i),i) for i in self.mapping.getCopySources()])
        return ret

    def buildList(self):
        c = 0
        for i,key in enumerate(self.mapping.keys()):
            Label(self.listFrame.interior(),text=self.formatKey(key))\
                 .grid(row=i+c,column=0,pady=1,padx=3)
            ssf = SubsetFrame(self.listFrame.interior(),self.mapping.getSubset(key),limit=1)
            self.subsetframes[key] = ssf
            ssf.grid(sticky="w",row=i,column=1)

    def onSave(self):
        self.pop.destroy()
        for key,ssf in self.subsetframes.items():
            self.mapping[key] = ssf.subset
        chimera.triggers.activateTrigger('configUpdated', None)
        
    def copyMapping(self):
        copyFrom = self.similars[self.mapVar.get()].mapping
        self.mapping.copyFrom(copyFrom)
        self.buildList()
开发者ID:crosslinks,项目名称:XlinkAnalyzer,代码行数:75,代码来源:item.py

示例2: __init__

# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import update [as 别名]
class Game:
    def __init__(self):
        self.root = Tk()
        self.frame1 = None
        self.frame2 = None
        self.w = None
        self.scoreC = None
        self.score = 0
        self.hor = True
        self.upid = self.downid = self.rightid = self.leftid = 0
        self.head = -1
        self.time = 700

    def home(self):
        self.frame1 = Frame(self.root, width=750, height=350, padx=250, bg="black")
        self.frame2 = Frame(self.root, height=250, width=750, bg="black", padx=25)
        self.root.wm_minsize(width=750, height=666)
        self.root.configure(bg="black")
        self.frame1.pack_propagate(0)
        self.frame1.update()
        self.frame1.configure(pady=self.frame1.cget("height") / 2.5)
        logo = PhotoImage(file="Game_Logo.gif")
        starth = Button(self.frame1, text="Hard", bg="orange", padx=25, pady=5,
                        font=Font(family="comic sans MS", size=10),
                        command=lambda: self.callgame(40))
        startm = Button(self.frame1, text="Medium", bg="teal", padx=25, pady=5,
                        font=Font(family="comic sans MS", size=10),
                        command=lambda: self.callgame(60))
        starte = Button(self.frame1, text="Easy", bg="orange", padx=25, pady=5,
                        font=Font(family="comic sans MS", size=10),
                        command=lambda: self.callgame(75))
        self.frame2.pack_propagate(0)
        exp = """        This is a game in which
        the arrow keys are used
        to move the snake around
        and to get points"""
        exf = Font(family="comic sans MS", size=20)
        Label(self.frame2, image=logo, bg="black", text=exp, padx=10).pack(side="right")
        Label(self.frame2, fg="white", bg="black", text=exp, justify="left", font=exf).pack(side="left")
        starte.grid(row=0, columnspan=2)
        startm.grid(row=0, columnspan=2, column=4, padx=18)
        starth.grid(row=0, columnspan=2, column=8)
        head = Font(family="comic sans MS", size=30)
        self.H=Label(self.root, text="SNAKES", font=head, fg="orange", bg="black", pady=10)
        self.H.pack()
        self.frame2.pack(expand=True)
        self.frame1.pack(expand=True)
        self.root.mainloop()

    def callgame(self, time):
        self.time = time
        self.game()

    def calldown(self, key):
        if self.hor:
            self.w.after_cancel(self.leftid)
            self.w.after_cancel(self.rightid)
            self.down(0)

    def callup(self, key):
        if self.hor:
            self.w.after_cancel(self.leftid)
            self.w.after_cancel(self.rightid)
            self.up(0)

    def callright(self, key):
        if not self.hor:
            self.w.after_cancel(self.upid)
            self.w.after_cancel(self.downid)
            self.right(0)

    def callleft(self, key):
        if not self.hor:
            self.w.after_cancel(self.upid)
            self.w.after_cancel(self.downid)
            self.left(0)

    def game(self):
        self.score = 0
        self.w = Canvas(self.root, width=750, height=500, relief="flat", highlightbackground="grey",
                        highlightthickness=10)
        self.frame1.destroy()
        self.frame2.destroy()
        self.root.configure(width=1000, padx=10)
        self.root.pack_propagate(0)
        self.w.configure(background="black")
        self.w.pack(side="left")
        self.w.create_line(300, 250, 450, 250, width=10, fill="teal")
        self.scoreC = Label(self.root, text="Score\n" + str(self.score), bg="black", fg="teal", padx=25, pady=35,
                            font=Font(family="comic sans MS", size=25))
        self.head = self.w.create_line(450, 250, 455, 250, width=10, fill="white")
        self.scoreC.pack(side="top")
        self.root.bind("<Up>", self.callup)
        self.root.bind("<Down>", self.calldown)
        self.root.bind("<Right>", self.callright)
        self.root.bind("<Left>", self.callleft)
        self.createFood()
        self.right(0)

    def down(self, i):
#.........这里部分代码省略.........
开发者ID:abhivijay96,项目名称:Python-snake-game,代码行数:103,代码来源:game.py

示例3: __init__

# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import update [as 别名]
class CWGUI:
    '''
    Draws the GUI and initiates the core components of the program.
    '''
    def __init__(self):
        self.root = Tk()
        self.root.title("CW")
        self.root.resizable(width=FALSE, height=FALSE)
        self.mainframe = Frame(self.root, bg='white', border=0)
        self.values = CONFIG()
        self.labels_pnames = []
        self.labels_status = []

        self.main_window(self.values)
    
    def main_window(self, values):
        '''
        Initiates the main components of the program, and draws the GUI.
        '''
#HEADER
        font_header = tkFont.Font(family="Helvetica", size=16, weight="bold")
        label_header = Label(self.mainframe, text="Campus-Warder",
            #fg="LightCyan3", 
            fg='LightCyan4',
            bg='white', font=font_header)
        label_header.pack(anchor=N, pady=5)
#BANDWIDTHUSAGE
        frame_bandwidth = Frame(self.mainframe, border=2, relief="groove",
            bg='white')

        label_bandwidth_decorator = Label(frame_bandwidth, text="Usage:\n",
            bg='white')
        label_bandwidth_decorator.pack(side=LEFT, padx=5)
        # Colors and font
        upcolor = color_indicator(values.parser.up, values.uplimit)
        downcolor = color_indicator(values.parser.down, values.downlimit)
        font_numbers = tkFont.Font(family="Helvetica", size=12, weight="bold")
        # Values
        label_up_decorator = Label(frame_bandwidth, bg='white', text="Up: ")
        label_up_decorator.pack(side=LEFT)
        self.label_up = Label(frame_bandwidth, bg='white', fg=upcolor,
            font=font_numbers, text=str(values.parser.up) + " MB")
        self.label_up.pack(side=LEFT)
        label_down_decorator = Label(frame_bandwidth, bg='white', 
            text=" /  Down: ")
        label_down_decorator.pack(side=LEFT)
        self.label_down = Label(frame_bandwidth, bg='white', fg=downcolor,
            text= str(values.parser.down) + " MB", font=font_numbers)
        self.label_down.pack(side=LEFT, padx= 5)

        frame_bandwidth.pack(side=TOP)
#PROGRAMS AND STATUS
        frame_status = Frame(self.mainframe, bg='white', border=2,
            relief="groove")
        frames_status = []

        for i in range(0, len(values.programs)):
            frames_status.append(Frame(frame_status, bg='white', border=0,
                relief='groove'))
            #Program display names
            self.labels_pnames.append(Label(frames_status[i], bg='white',
                text=values.programs[i].display_name + ": "))
            self.labels_pnames[i].pack(side=LEFT, padx=6)
            #Status
            self.labels_status.append(Label(frames_status[i], bg='white',
                text=values.programs[i].status))
            self.labels_status[i].pack(side=RIGHT, padx=6)

            frames_status[i].pack(side=TOP, fill=X) 
#PACK
        frame_status.pack(side=TOP, fill=X, anchor=W)
        self.mainframe.pack()
#ENDLESS LOOP
        #On the first run, wait 3 seconds so that the GUI
        #has a chance to draw
        self.root.after(3000, self.update)

    def update(self):
        '''
        Updates the status of the programs, depending on the output of the OS
        tasklist command
        '''
        #Update every 2 minutes
        self.root.after(60*1000*2, self.update)
#BANDWIDTH STATUS
        # Colors
        bandwidth = self.values.get_bandwidth()
        upcolor = color_indicator(bandwidth[0], self.values.uplimit)
        downcolor = color_indicator(bandwidth[1], self.values.downlimit)
        # Values
        self.label_up["fg"] = upcolor,
        self.label_up["text"] = str(self.values.parser.up) + " MB"
        self.label_up.update()
        self.label_down["fg"] = downcolor,
        self.label_down["text"] = str(self.values.parser.down) + " MB"
        self.label_down.update()
#PROGRAM STATUS
        if self.values.os == "Windows":
            ps_output = os.popen("tasklist").read()
        else:
#.........这里部分代码省略.........
开发者ID:sinzim,项目名称:Campus-Warder,代码行数:103,代码来源:cw.py


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