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


Python Tk.after方法代码示例

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


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

示例1: ua_win_tk

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
def ua_win_tk(url, pipe = None):
    from tkinter import Tk, Frame, Label, Entry, StringVar, BOTH, Button, RIGHT
    import sys
    sys.stdout.flush()
    instructions = "Visit the following URL to authorize the application:"
    response = {"x": False}
    root = Tk()
    root.title("oAuth2 Authorization Required")
    webbox = Frame(root)
    instructions = Label(webbox, text = instructions)
    instructions.pack(padx = 5, pady = 5)
    urlstr = StringVar(value = url)
    urlbox = Entry(webbox, textvariable = urlstr, state = "readonly")
    urlbox.pack(padx = 5, pady = 5)
    def open_browser():
        from subprocess import Popen
        p = Popen(["sensible-browser", url])
    browserbutton = Button(webbox, text = "Open in web browser", command = open_browser)
    browserbutton.pack(padx = 5, pady = 5)
    webbox.pack(fill = BOTH, expand = 1)
    if pipe:
        def poll():
            if pipe.poll():
                root.destroy()
                #Mutability ftw... wat
                response["x"] = True
            else:
                root.after(300, poll)
        root.after(300, poll)
    cancelbutton = Button(root, text = "Cancel", command = root.destroy)
    cancelbutton.pack(side = RIGHT, padx = 5, pady = 5)
    root.mainloop()
    return response["x"]
开发者ID:pyokagan,项目名称:pyoauth2client,代码行数:35,代码来源:ui.py

示例2: showMainValues

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
def showMainValues():

    global tkroot
    global labels
    global mframe
    global values

    from tkinter import Tk, N, W
    from tkinter.ttk import LabelFrame, Label

    # first run, set up the thingy
    print("Setting up Main Values...")
    init_parse(getMainValues, _parse_main_values_xml, values)

    sleep(0.5)

    print("Setting up Advanced Values...")
    init_parse(getAdvancedValues, _parse_adv_values_xml, values)

    print("initializing tkinter interface...")

    tkroot = Tk()
    mframe = LabelFrame(tkroot, text="Main Frame")
    labels = {}
    for group in values:
        lframe = LabelFrame(mframe, text=group)
        labels[group] = OrderedDict()
        labels[group]['frame'] = lframe
        for param, pv in values[group].items():
            labels[group][param] = {}
            plabel = Label(lframe, text=param)
            vlabel = Label(lframe, text=pv)
            labels[group][param]['plabel'] = plabel
            labels[group][param]['vlabel'] = vlabel

    mframe.grid()
    for i, group in enumerate(labels):
        for param in labels[group]:
            if param == 'frame':
                labels[group][param].grid(column=i, row=0, sticky=N)
            else:
                labels[group][param]['plabel'].grid(sticky=W)
                labels[group][param]['vlabel'].grid(sticky=W)

    tkroot.grid()

    print('setting up polling intervals')

    tkroot.after(500, poll_main_values)
    tkroot.after(750, poll_adv_values)

    print('Ready')

    tkroot.mainloop()
    print("afterloop")
开发者ID:nitetrain8,项目名称:scripts,代码行数:57,代码来源:dummyhello.py

示例3: main

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
def main(board):
    root = Tk()
    app = App(root, board)

    def update_gui():
        root.after(5, update_gui)
        app.update()

    root.after(0, update_gui)
    root.mainloop()

    board.stop()
开发者ID:alej0varas,项目名称:pybolator,代码行数:14,代码来源:pybgui.py

示例4: Timer

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
    class Timer(object):
        def __init__(self, func):
            self.app = Tk()
            self.app.withdraw()
            self.func = func

        def on_timer(self):
            self.func()
            self.app.after(poll_interval, self.on_timer)

        def start(self):
            self.on_timer()  # Call it once to get things going.
            self.app.mainloop()
开发者ID:CaptainAL,项目名称:Spyder,代码行数:15,代码来源:eventloops.py

示例5: TkTimerCore

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
class TkTimerCore(TimerCore):
    def __init__(self, *args, title, font_size, **kwargs):
        def close_handler(event):
            self.close()
        def clicked_handler(event):
            self.interact()

        self.master = Tk()
        self.master.wm_title(title)
        self.master.bind('<Destroy>', close_handler)
        self.label = Label(self.master, font='Sans {}'.format(int(font_size)))
        self.label.pack(expand=True)

        self.control = Toplevel()
        self.control.wm_title(title + ' (control)')
        self.control.minsize(150, 150)
        self.control.bind('<Destroy>', close_handler)
        self.button = Button(self.control, text='Start/Pause')
        self.button.bind('<ButtonRelease>', clicked_handler)
        self.button.pack(expand=True)

        self.timeout_running = False

        super().__init__(*args, **kwargs)

    def start_timeout(self):
        assert self.timeout_running is False
        def timeout_call():
            if self.timeout_running:
                self.update()
                self.master.after(25, timeout_call)
        self.timeout_running = True
        timeout_call()

    def stop_timeout(self):
        assert self.timeout_running is True
        self.timeout_running = False

    def mainloop(self):
        return self.master.mainloop()

    def shutdown(self):
        self.master.quit()

    def set_label_text(self, text, finished=False):
        self.label.config(text=text)
        if finished:
            self.label.config(fg='red')
开发者ID:tifv,项目名称:jtimer,代码行数:50,代码来源:tk.py

示例6: main

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
def main():  
    root = Tk()

    ex = GPIOSim(root)

    def poll():
        root.after(500, poll)
    root.after(500, poll)

    def updateHandler(signum,frame):
        ex.updateUI()

    signal.signal(signal.SIGUSR1,updateHandler)

    root.geometry(ex.WIN_SIZE)
    root.mainloop()  
开发者ID:TuxEatPi,项目名称:GPIOSim,代码行数:18,代码来源:gui.py

示例7: Tetris

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
class Tetris():
    def init(self):
        self.root = Tk()
        self.root.title("Tetris! By the Pritz Brothers")

        self.board = Board(self.root)
        self.current_piece = Piece(self.board)

        self.time_interval = 500
        self.timer()
        
        self.root.mainloop()

    def timer(self):
        self.root.after(self.time_interval, self.timer)
        self.current_piece.fall()
开发者ID:pritz2,项目名称:Tketris,代码行数:18,代码来源:Tketris.py

示例8: UI

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
class UI():
    
    SYSTEM_REFRESH_RATE = 1000
    
    def __init__(self,inhandler,outhandler):
        self.executors = []
        self.outh = outhandler
        self.outh.add_listener(self)
        self.root = Tk()
        self.app = Text_Output(self.root,inhandler)
        self.root.after(2000, self.outh.update)
        self.root.after(self.SYSTEM_REFRESH_RATE, self.execute)
        
        
    def update(self):
        self.app.config(state=NORMAL)
        self.app.delete(1.0, END)
        self.app.insert('end', '{}'.format(self.outh.visual_output))
        self.app.config(state=DISABLED)
    
    def add_executor(self,exe):
        self.executors.append(exe)
        
    def execute(self):
        for exe in self.executors:
            exe.update()
        self.root.after(self.SYSTEM_REFRESH_RATE, self.execute)
        
    def start(self):
        self.root.mainloop()
开发者ID:daviaws,项目名称:missionText,代码行数:32,代码来源:UI.py

示例9: displaywarning

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
__author__ = 'tkessler'

from tkinter import Tk
from tkinter.messagebox import showinfo

def displaywarning():
    showinfo("Wahoo title", "wahoo message")

mainwin = Tk() #main TK loop...
mainwin.after(5500, displaywarning) # displaywarning provides fn name only...
#mainwin.after(5500, displaywarning()) # displaywarning() calls displaywarning immediately
#mainwin.after(5500, showinfo("Wahoo title", "wahoo message")) # showinfo() calls showinfo immediately
mainwin.mainloop()
开发者ID:tkessler45,项目名称:Workbench,代码行数:15,代码来源:tkinterPreview.py

示例10: __init__

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
class CollocationsView:
    _BACKGROUND_COLOUR='#FFF' #white

    def __init__(self):
        self.queue = q.Queue()
        self.model = CollocationsModel(self.queue)
        self.top = Tk()
        self._init_top(self.top)
        self._init_menubar()
        self._init_widgets(self.top)
        self.load_corpus(self.model.DEFAULT_CORPUS)
        self.after = self.top.after(POLL_INTERVAL, self._poll)

    def _init_top(self, top):
        top.geometry('550x650+50+50')
        top.title('NLTK Collocations List')
        top.bind('<Control-q>', self.destroy)
        top.protocol('WM_DELETE_WINDOW', self.destroy)
        top.minsize(550,650)

    def _init_widgets(self, parent):
        self.main_frame = Frame(parent, dict(background=self._BACKGROUND_COLOUR, padx=1, pady=1, border=1))
        self._init_corpus_select(self.main_frame)
        self._init_results_box(self.main_frame)
        self._init_paging(self.main_frame)
        self._init_status(self.main_frame)
        self.main_frame.pack(fill='both', expand=True)

    def _init_corpus_select(self, parent):
        innerframe = Frame(parent, background=self._BACKGROUND_COLOUR)
        self.var = StringVar(innerframe)
        self.var.set(self.model.DEFAULT_CORPUS)
        Label(innerframe, justify=LEFT, text=' Corpus: ', background=self._BACKGROUND_COLOUR, padx = 2, pady = 1, border = 0).pack(side='left')

        other_corpora = list(self.model.CORPORA.keys()).remove(self.model.DEFAULT_CORPUS)
        om = OptionMenu(innerframe, self.var, self.model.DEFAULT_CORPUS, command=self.corpus_selected, *self.model.non_default_corpora())
        om['borderwidth'] = 0
        om['highlightthickness'] = 1
        om.pack(side='left')
        innerframe.pack(side='top', fill='x', anchor='n')

    def _init_status(self, parent):
        self.status = Label(parent, justify=LEFT, relief=SUNKEN, background=self._BACKGROUND_COLOUR, border=0, padx = 1, pady = 0)
        self.status.pack(side='top', anchor='sw')

    def _init_menubar(self):
        self._result_size = IntVar(self.top)
        menubar = Menu(self.top)

        filemenu = Menu(menubar, tearoff=0, borderwidth=0)
        filemenu.add_command(label='Exit', underline=1,
                   command=self.destroy, accelerator='Ctrl-q')
        menubar.add_cascade(label='File', underline=0, menu=filemenu)

        editmenu = Menu(menubar, tearoff=0)
        rescntmenu = Menu(editmenu, tearoff=0)
        rescntmenu.add_radiobutton(label='20', variable=self._result_size,
                     underline=0, value=20, command=self.set_result_size)
        rescntmenu.add_radiobutton(label='50', variable=self._result_size,
                     underline=0, value=50, command=self.set_result_size)
        rescntmenu.add_radiobutton(label='100', variable=self._result_size,
                     underline=0, value=100, command=self.set_result_size)
        rescntmenu.invoke(1)
        editmenu.add_cascade(label='Result Count', underline=0, menu=rescntmenu)

        menubar.add_cascade(label='Edit', underline=0, menu=editmenu)
        self.top.config(menu=menubar)

    def set_result_size(self, **kwargs):
        self.model.result_count = self._result_size.get()

    def _init_results_box(self, parent):
        innerframe = Frame(parent)
        i1 = Frame(innerframe)
        i2 = Frame(innerframe)
        vscrollbar = Scrollbar(i1, borderwidth=1)
        hscrollbar = Scrollbar(i2, borderwidth=1, orient='horiz')
        self.results_box = Text(i1,
                    font=tkinter.font.Font(family='courier', size='16'),
                    state='disabled', borderwidth=1,
                    yscrollcommand=vscrollbar.set,
                    xscrollcommand=hscrollbar.set, wrap='none', width='40', height = '20', exportselection=1)
        self.results_box.pack(side='left', fill='both', expand=True)
        vscrollbar.pack(side='left', fill='y', anchor='e')
        vscrollbar.config(command=self.results_box.yview)
        hscrollbar.pack(side='left', fill='x', expand=True, anchor='w')
        hscrollbar.config(command=self.results_box.xview)
        #there is no other way of avoiding the overlap of scrollbars while using pack layout manager!!!
        Label(i2, text='   ', background=self._BACKGROUND_COLOUR).pack(side='left', anchor='e')
        i1.pack(side='top', fill='both', expand=True, anchor='n')
        i2.pack(side='bottom', fill='x', anchor='s')
        innerframe.pack(side='top', fill='both', expand=True)

    def _init_paging(self, parent):
        innerframe = Frame(parent, background=self._BACKGROUND_COLOUR)
        self.prev = prev = Button(innerframe, text='Previous', command=self.previous, width='10', borderwidth=1, highlightthickness=1, state='disabled')
        prev.pack(side='left', anchor='center')
        self.next = next = Button(innerframe, text='Next', command=self.__next__, width='10', borderwidth=1, highlightthickness=1, state='disabled')
        next.pack(side='right', anchor='center')
        innerframe.pack(side='top', fill='y')
#.........这里部分代码省略.........
开发者ID:CaptainAL,项目名称:Spyder,代码行数:103,代码来源:collocations_app.py

示例11: int

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
        #pin = clicked PIN

        if self.currState[pin]==self.STATE_GPIO_IN:

            self.currValue[pin] = int ( not bool(self.currValue[pin]))

            self.updateFile()

            self.updateUI()



#End Class


  
root = Tk()

ex = GPIOSim(root)

def poll():
    root.after(500, poll)
root.after(500, poll)

def updateHandler(signum,frame):
    ex.updateUI()

signal.signal(signal.SIGUSR1,updateHandler)

root.geometry(ex.WIN_SIZE)
root.mainloop()  
开发者ID:ekapujiw2002,项目名称:GPIOSim,代码行数:33,代码来源:GPIOSim.py

示例12: __init__

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

#.........这里部分代码省略.........
                (nx, ny) = (x-1, y)
            elif act == Action.right:
                (nx, ny) = (x+1, y)
            real_pos = (
                max(0, min(self.width-1, nx)),
                max(0, min(self.height-1, ny)),
            )
            
            self.player_pos = real_pos
            pen = 0 if real_pos == (nx, ny) else -1
            rew += pen
        elif act == Action.pick and self.state == State.start:
            if self.obj_pos == self.player_pos:
                self.state = State.picked
                if self.first_pick:
                    self.first_pick = False
                    rew += 1
                if (not self.task_type & TaskType.put):
                    self.state = State.end
        elif act == Action.put and self.state == State.picked:
            if self.mark_pos == self.player_pos:
                self.state = State.end
                rew += 1
            else:
                self.state = State.start
                self.obj_pos = self.player_pos

        if self.state == State.end:
            rew += 5
        return rew

    def render(self):
        # clear canvas
        self.draw.rectangle((0, 0, self.frame_width, self.frame_height),
                            fill='black')

        # draw obj
        if self.obj_pos and self.state == State.start:
            px, py = self._get_frame_pos(self.obj_pos)
            self.draw.rectangle((px - 2, py - 2, px + 2, py + 2), fill='green')
            
        # draw mark
        if self.mark_pos:
            px, py = self._get_frame_pos(self.mark_pos)
            self.draw.rectangle((px - 2, py - 2, px + 2, py + 2), outline='white')

        # draw player
        px, py = self._get_frame_pos(self.player_pos)
        loc = (px - 2, py - 2, px + 2, py + 2)
        if self.state == State.picked:
            self.draw.ellipse(loc, fill=(0, 255, 255, 0))
        else:
            self.draw.ellipse(loc, fill='blue')

        if self.show_gui:
            gui_img = self.image.resize((self.frame_width * self.gui_amp,
                                         self.frame_height * self.gui_amp))
            self.pi = ImageTk.PhotoImage(gui_img)
            canvas_img = self.canvas.create_image(0, 0, anchor=NW,
                                                  image=self.pi)
            # self.canvas.create_text((self.width*self.gui_amp-20, 5), 
                                    # fill='white', text=str(self.))

            if not self.human_play:
                self.tk.update()

    def get_bitmap(self):
        arr = np.array(self.image.getdata()).reshape(self.image_shape)
        return arr.astype('float32') / 256.0

    def gui_step(self):
        if self.last_act is not None:
            rew = self.step(self.last_act)
            self.last_act = None
        else:
            rew = self.step(None)
        if abs(rew) > 1e-9:
            print('Get reward = %.2f' % rew)
        self.render()
        self.tk.after(1000//self.FPS, self.gui_step)

    def gui_start(self):
        self.canvas.bind("<Key>", self.gui_onkey)
        self.canvas.focus_set()
        self.tk.after(1000//self.FPS, self.gui_step)
        self.tk.mainloop()

    def gui_onkey(self, event):
        if event.keycode == 111 or event.keycode == 8320768:
            self.last_act = Action.up
        elif event.keycode == 116 or event.keycode == 8255233:
            self.last_act = Action.down
        elif event.keycode == 113 or event.keycode == 8124162:
            self.last_act = Action.left
        elif event.keycode == 114 or event.keycode == 8189699:
            self.last_act = Action.right
        elif event.keycode == 53 or event.keycode == 458872:
            self.last_act = Action.pick
        elif event.keycode == 52 or event.keycode == 393338:
            self.last_act = Action.put
开发者ID:kevin00036,项目名称:gym,代码行数:104,代码来源:game.py

示例13: main

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
def main():
    root = Tk()
    ex = Speedometer(root)
    root.geometry("400x400+300+300")
    root.after(2000, task())
    root.mainloop()  
开发者ID:probststefan,项目名称:RaspberryPi-Regattasegeln,代码行数:8,代码来源:window.py

示例14: __init__

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import after [as 别名]
class CollocationsView:
    _BACKGROUND_COLOUR = "#FFF"  # white

    def __init__(self):
        self.queue = q.Queue()
        self.model = CollocationsModel(self.queue)
        self.top = Tk()
        self._init_top(self.top)
        self._init_menubar()
        self._init_widgets(self.top)
        self.load_corpus(self.model.DEFAULT_CORPUS)
        self.after = self.top.after(POLL_INTERVAL, self._poll)

    def _init_top(self, top):
        top.geometry("550x650+50+50")
        top.title("NLTK Collocations List")
        top.bind("<Control-q>", self.destroy)
        top.protocol("WM_DELETE_WINDOW", self.destroy)
        top.minsize(550, 650)

    def _init_widgets(self, parent):
        self.main_frame = Frame(parent, dict(background=self._BACKGROUND_COLOUR, padx=1, pady=1, border=1))
        self._init_corpus_select(self.main_frame)
        self._init_results_box(self.main_frame)
        self._init_paging(self.main_frame)
        self._init_status(self.main_frame)
        self.main_frame.pack(fill="both", expand=True)

    def _init_corpus_select(self, parent):
        innerframe = Frame(parent, background=self._BACKGROUND_COLOUR)
        self.var = StringVar(innerframe)
        self.var.set(self.model.DEFAULT_CORPUS)
        Label(
            innerframe, justify=LEFT, text=" Corpus: ", background=self._BACKGROUND_COLOUR, padx=2, pady=1, border=0
        ).pack(side="left")

        other_corpora = list(self.model.CORPORA.keys()).remove(self.model.DEFAULT_CORPUS)
        om = OptionMenu(
            innerframe,
            self.var,
            self.model.DEFAULT_CORPUS,
            command=self.corpus_selected,
            *self.model.non_default_corpora()
        )
        om["borderwidth"] = 0
        om["highlightthickness"] = 1
        om.pack(side="left")
        innerframe.pack(side="top", fill="x", anchor="n")

    def _init_status(self, parent):
        self.status = Label(
            parent, justify=LEFT, relief=SUNKEN, background=self._BACKGROUND_COLOUR, border=0, padx=1, pady=0
        )
        self.status.pack(side="top", anchor="sw")

    def _init_menubar(self):
        self._result_size = IntVar(self.top)
        menubar = Menu(self.top)

        filemenu = Menu(menubar, tearoff=0, borderwidth=0)
        filemenu.add_command(label="Exit", underline=1, command=self.destroy, accelerator="Ctrl-q")
        menubar.add_cascade(label="File", underline=0, menu=filemenu)

        editmenu = Menu(menubar, tearoff=0)
        rescntmenu = Menu(editmenu, tearoff=0)
        rescntmenu.add_radiobutton(
            label="20", variable=self._result_size, underline=0, value=20, command=self.set_result_size
        )
        rescntmenu.add_radiobutton(
            label="50", variable=self._result_size, underline=0, value=50, command=self.set_result_size
        )
        rescntmenu.add_radiobutton(
            label="100", variable=self._result_size, underline=0, value=100, command=self.set_result_size
        )
        rescntmenu.invoke(1)
        editmenu.add_cascade(label="Result Count", underline=0, menu=rescntmenu)

        menubar.add_cascade(label="Edit", underline=0, menu=editmenu)
        self.top.config(menu=menubar)

    def set_result_size(self, **kwargs):
        self.model.result_count = self._result_size.get()

    def _init_results_box(self, parent):
        innerframe = Frame(parent)
        i1 = Frame(innerframe)
        i2 = Frame(innerframe)
        vscrollbar = Scrollbar(i1, borderwidth=1)
        hscrollbar = Scrollbar(i2, borderwidth=1, orient="horiz")
        self.results_box = Text(
            i1,
            font=tkinter.font.Font(family="courier", size="16"),
            state="disabled",
            borderwidth=1,
            yscrollcommand=vscrollbar.set,
            xscrollcommand=hscrollbar.set,
            wrap="none",
            width="40",
            height="20",
            exportselection=1,
#.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:PrologMUD,代码行数:103,代码来源:collocations_app.py

示例15: Graphics

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

#.........这里部分代码省略.........
        logging.debug('Graphics.update() called')
        
        # put state in updateQueue
        self.updateQueue.put(state)
       
    def _update(self, event=None):
        '''
        Internal update function which is injected into the tkinter main loop.
        
        @note: _update() should never be called directly, it should only ever be registered in the tkinter main loop.
        To notify the Graphics object that it needs to update, call Graphics.update() instead.
        '''
        
        # =================
        # CHECK UPDATE FLAG
        # =================
        
        # only update if there are queued updates
        # otherwise reschedule the update method without re-rendering the graphics
        if not self.updateQueue.empty():
            
            # remove next queued update
            board = self.updateQueue.get()
        
            # ======================
            # CLEAR DESTROYED ACTORS
            # ======================
            
            for key in board.destroyed:
                if self.actorGraphics.get(key) != None:
                    
                    # delete graphics object using the stashed key
                    self.canvas.delete(self.actorGraphics[key])
                    
                    # delete stashed key
                    del self.actorGraphics[key];
            
            # ===============
            # UPDATE GRAPHICS
            # ===============
            
            for key in board.actors:
                self.drawActor(board.actors[key])
        
        # reschedule update
        self.tk_root.after(self.delay, self._update)
        
    def exit(self, event=None):
        '''
        Ends the Tkinter main loop and exits the game.
        '''
        
        # set exit flag
        self.exitFlag = True
        
        # kill tk mainloop
        self.tk_root.quit()
        
    def run(self):
        '''
        Initializes the tkinter graphics and starts the mainloop.
        '''
        
        logging.info('Graphics thread started')
        
        # =========================
        # INITIALIZE TKINTER STUFFS
        # =========================
        
        # reset flags
        self.updateFlag = False
        self.exitFlag = False
        
        # initialize tk_root
        self.tk_root = Tk()
        
        # DEBUGTASTIC CODE - binds the update method to escape for stepwise debugging
#         self.tk_root.bind("<space>", self.update)
        
        # binds the exit method to the escape key
        self.tk_root.bind("<Escape>", self.exit)
        
        # forces tkinter to call exit() when the window is closed (hitting the x button)
        self.tk_root.protocol("WM_DELETE_WINDOW", self.exit)
        
        # initialize tk canvas object
        self.canvas = Canvas(self.tk_root)
        
        logging.debug('canvas initialized to {}'.format(self.canvas))

        # set canvas width and height to the number of tiles times the number of pixels per tile
        self.canvas = Canvas(self.tk_root, width = self.boardSize * self.TILE_SIZE, height = self.boardSize * self.TILE_SIZE)
        self.canvas.grid(column=0, row=0, sticky=(N, W, E, S)) # I don't even know what this is doing
              
        # ===============
        # START MAIN LOOP
        # ===============
        
        self.tk_root.after(10, self._update)
        self.tk_root.mainloop()
开发者ID:CSSDePaul,项目名称:Computerized-Robot-Arena-Program,代码行数:104,代码来源:graphics.py


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