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


Python Tk.event_generate方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import event_generate [as 别名]
class gephiController:
    def __init__(self, data, appCallback=None, minValue=0.0, maxValue=1.0, logScale=False):
        self.data = data
        numBins = len(data)-1
        
        self.master = Tk()
        self.master.geometry("%dx%d%+d%+d" % (WIDTH,HEIGHT,50,50))
        self.master.resizable(False, False)
        
        self.histogram = histogramWidget(self.master,0,0,WIDTH,HEIGHT,self.data,logScale=logScale,callback=self.callApp)
        
        self.current = numBins
        self.currentValue = self.data[maxValue][0]
        
        self.appCallback = appCallback
        if self.appCallback != None:
            self.master.bind("<<appCallback>>",self.runAppCall)
        self.master.bind("<<Update>>",self.runUpdate)
    
    def mainloop(self):
        self.master.mainloop()
    
    def runUpdate(self, event):
        self.histogram.update(self.current)
    
    def runAppCall(self,event):
        self.appCallback(self.currentValue)
    
    def callApp(self, value):
        self.currentValue = value
        self.master.event_generate("<<appCallback>>",when="tail")
    
    def update(self, current):
        self.current = current
        self.master.event_generate("<<Update>>",when="tail")
开发者ID:alex-r-bigelow,项目名称:compreheNGSive,代码行数:37,代码来源:gephiGui.py

示例2: NvimTk

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

#.........这里部分代码省略.........
        self._bg = "#{0:0{1}x}".format(bg, 6)

    def _tk_redraw_canvas(self, width, height):
        if self._canvas:
            self._canvas.destroy()
        self._fnormal = Font(family='Monospace', size=13)
        self._fbold = Font(family='Monospace', weight='bold', size=13)
        self._fitalic = Font(family='Monospace', slant='italic', size=13)
        self._fbolditalic = Font(family='Monospace', weight='bold',
                                 slant='italic', size=13)
        self._colsize = self._fnormal.measure('A')
        self._rowsize = self._fnormal.metrics('linespace')
        self._canvas = Canvas(self._root, width=self._colsize * width,
                              height=self._rowsize * height)
        self._tk_fill_region(0, height - 1, 0, width - 1)
        self._cursor_row = 0
        self._cursor_col = 0
        self._scroll_top = 0
        self._scroll_bot = height - 1
        self._scroll_left = 0
        self._scroll_right = width - 1
        self._width, self._height = (width, height,)
        self._canvas.pack()

    def _tk_fill_region(self, top, bot, left, right):
        # create columns from right to left so the left columns have a
        # higher z-index than the right columns. This is required to
        # properly display characters that cross cell boundary
        for rownum in range(bot, top - 1, -1):
            for colnum in range(right, left - 1, -1):
                x1 = colnum * self._colsize
                y1 = rownum * self._rowsize
                x2 = (colnum + 1) * self._colsize
                y2 = (rownum + 1) * self._rowsize
                # for each cell, create two items: The rectangle is used for
                # filling background and the text is for cell contents.
                self._canvas.create_rectangle(x1, y1, x2, y2,
                                              fill=self._background, width=0)
                self._canvas.create_text(x1, y1, anchor='nw',
                                         font=self._fnormal, width=1,
                                         fill=self._foreground, text=' ')

    def _tk_clear_region(self, top, bot, left, right):
        self._tk_tag_region('clear', top, bot, left, right)
        self._canvas.itemconfig('clear', fill=self._bg)
        self._canvas.dtag('clear', 'clear')

    def _tk_destroy_region(self, top, bot, left, right):
        self._tk_tag_region('destroy', top, bot, left, right)
        self._canvas.delete('destroy')
        self._canvas.dtag('destroy', 'destroy')

    def _tk_tag_region(self, tag, top, bot, left, right):
        x1, y1 = self._tk_get_coords(top, left)
        x2, y2 = self._tk_get_coords(bot, right)
        self._canvas.addtag_overlapping(tag, x1, y1, x2 + 1, y2 + 1)

    def _tk_get_coords(self, row, col):
        x = col * self._colsize
        y = row * self._rowsize
        return x, y

    def _tk_key(self, event):
        if 0xffe1 <= event.keysym_num <= 0xffee:
            # this is a modifier key, ignore. Source:
            # https://www.tcl.tk/man/tcl8.4/TkCmd/keysyms.htm
            return
        # Translate to Nvim representation of keys
        send = []
        if event.state & 0x1:
            send.append('S')
        if event.state & 0x4:
            send.append('C')
        if event.state & (0x8 | 0x80):
            send.append('A')
        special = len(send) > 0
        key = event.char
        if _is_invalid_key(key):
            special = True
            key = event.keysym
        send.append(SPECIAL_KEYS.get(key, key))
        send = '-'.join(send)
        if special:
            send = '<' + send + '>'
        nvim = self._nvim
        nvim.session.threadsafe_call(lambda: nvim.input(send))

    def _nvim_event_loop(self):
        self._nvim.session.run(self._nvim_request,
                               self._nvim_notification,
                               lambda: self._nvim.attach_ui(80, 24))
        self._root.event_generate('<<nvim_detach>>', when='tail')

    def _nvim_request(self, method, args):
        raise Exception('This UI does not implement any methods')

    def _nvim_notification(self, method, args):
        if method == 'redraw':
            self._nvim_updates.append(args)
            self._root.event_generate('<<nvim_redraw>>', when='tail')
开发者ID:timeyyy,项目名称:pytknvim,代码行数:104,代码来源:tarruda.py

示例3: YTPlaylistGUI

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import event_generate [as 别名]
class YTPlaylistGUI(UI):
    LOGIN_COMPLETE_EVENT = "<<LoginComplete>>"
    PLAYLIST_LIST_FETCH_COMPLETE_EVENT = "<<PlalistListFetched>>"
    PLAYLIST_SAVED_EVENT = "<<PlaylistSaved>>"

    def __init__(self, playlist_manager):
        super(YTPlaylistGUI, self).__init__()
        self.playlist_manager = playlist_manager
        self.workerThread = None
        self.last_exception = None
        self.username = None
        self._login_dialog = None
        self._loading_playlists_dialog = None

    def _create_login_window(self):
        self.root = Tk()
        self.root.geometry("280x150")
        self.root.title(self.YTPLAYLIST_LOGIN_WINDOW_TITLE)
        self.root.bind(self.LOGIN_COMPLETE_EVENT, self._login_complete)
        Button(self.root, text=self.YTPLAYLIST_LOGIN_BUTTON_TEXT,
               command=self.login).pack(side=Tkinter.TOP,
                                        pady=20, padx=20, expand=True, fill=Tkinter.BOTH)
        Button(self.root, text=self.YTPLAYLIST_NOLOGIN_BUTTON_TEXT,
               command=self.skip_login).pack(side=Tkinter.TOP,
                                             pady=20, padx=20, expand=True, fill=Tkinter.BOTH)

    def _create_playlists_window(self):
        if self.root:
            self.root.destroy()
        self.root = Tk()
        self.root.geometry("300x{0}".format(280 if self.playlist_manager.is_logged_in else 250))
        self.root.title(self.YTPLAYLIST_PLAYLISTS_WINDOW_TITLE)
        if self.playlist_manager.is_logged_in:
            Button(self.root, text=self.YTPLAYLIST_DESTROY_CREDENTIALS_BUTTON_TEXT,
                   command=self.logout).pack(side=Tkinter.TOP, padx=20, pady=(10, 5), fill=Tkinter.X)
        scrollbar = Scrollbar(self.root, orient=Tkinter.VERTICAL)
        self.playlist_list = Listbox(self.root, yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.playlist_list.yview)
        Button(self.root, text=self.YTPLAYLIST_EXPORT_BUTTON_TEXT,
               command=self._export_playlist_item).pack(side=Tkinter.BOTTOM,
                                                        padx=20, pady=(5, 10), fill=Tkinter.X)
        self.playlist_list.pack(side=Tkinter.LEFT, padx=(5, 0), pady=5, expand=True, fill=Tkinter.BOTH)
        scrollbar.pack(side=Tkinter.LEFT, padx=(0, 5), pady=5, fill=Tkinter.Y)
        self.root.bind(self.PLAYLIST_LIST_FETCH_COMPLETE_EVENT,
                       self._playlist_list_fetched)
        self.root.bind(self.PLAYLIST_SAVED_EVENT, self._playlist_saved)

    def start(self):
        self._create_login_window()
        self.root.mainloop()

    def _login_async(self):
        try:
            self.playlist_manager.login()
        except Exception as e:
            self.last_exception = e
        self.root.event_generate(self.LOGIN_COMPLETE_EVENT, when="tail")

    def login(self):
        self.workerThread = threading.Thread(target=self._login_async)
        self.workerThread.start()
        self._login_dialog = _WorkingDialog(self.root, "Logging in...")

    def logout(self):
        self.playlist_manager.destroy_credentials()
        self.root.destroy()

    def skip_login(self):
        self.username =\
            tkSimpleDialog.askstring(
                "Username", "Specify the playlist owner's username",
                parent=self.root)
        self.playlist_manager.skip_login()
        self._create_playlists_window()
        self.display_playlists()

    def _login_complete(self, _):
        del self._login_dialog
        self.__handle_exceptions()
        self._create_playlists_window()
        self.display_playlists()

    def display_playlists(self):
        self._loading_playlists_dialog =\
            _WorkingDialog(self.root, "Loading playlists")
        self.workerThread =\
            threading.Thread(target=self._fetch_playlists_async)
        self.workerThread.start()

    def _fetch_playlists_async(self):
        try:
            if self.playlist_manager.is_logged_in:
                result = self.playlist_manager.list_playlists()
            else:
                result = self.playlist_manager.list_playlists(self.username)
            self.playlist_data = result
        except Exception as e:
            self.last_exception = e
        self.root.event_generate(self.PLAYLIST_LIST_FETCH_COMPLETE_EVENT, when="tail")

#.........这里部分代码省略.........
开发者ID:yavorpap,项目名称:ytplaylistexport,代码行数:103,代码来源:ui.py

示例4: __init__

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

#.........这里部分代码省略.........
        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')
        self.reset_current_page()

    def reset_current_page(self):
        self.current_page = -1

    def _bind_event_handlers(self):
        self.top.bind(CORPUS_LOADED_EVENT, self.handle_corpus_loaded)
        self.top.bind(ERROR_LOADING_CORPUS_EVENT, self.handle_error_loading_corpus)

    def handle_error_loading_corpus(self, event):
        self.status['text'] = 'Error in loading ' + self.var.get()
        self.unfreeze_editable()
        self.clear_results_box()
        self.freeze_editable()
        self.reset_current_page()

    def handle_corpus_loaded(self, event):
        self.status['text'] = self.var.get() + ' is loaded'
        self.unfreeze_editable()
        self.clear_results_box()
        self.reset_current_page()
        #self.next()
        collocations = self.model.next(self.current_page + 1)
        self.write_results(collocations)
        self.current_page += 1

    def corpus_selected(self, *args):
        new_selection = self.var.get()
        self.load_corpus(new_selection)

    def previous(self):
        self.freeze_editable()
        collocations = self.model.prev(self.current_page - 1)
        self.current_page= self.current_page - 1
        self.clear_results_box()
        self.write_results(collocations)
        self.unfreeze_editable()

    def next(self):
        self.freeze_editable()
        collocations = self.model.next(self.current_page + 1)
        self.clear_results_box()
        self.write_results(collocations)
        self.current_page += 1
        self.unfreeze_editable()

    def load_corpus(self, selection):
        if self.model.selected_corpus != selection:
            self.status['text'] = 'Loading ' + selection + '...'
            self.freeze_editable()
            self.model.load_corpus(selection)

    def freeze_editable(self):
        self.prev['state'] = 'disabled'
        self.next['state'] = 'disabled'

    def clear_results_box(self):
        self.results_box['state'] = 'normal'
        self.results_box.delete("1.0", END)
        self.results_box['state'] = 'disabled'

    def fire_event(self, event):
        #Firing an event so that rendering of widgets happen in the mainloop thread
        self.top.event_generate(event, when='tail')

    def destroy(self, *e):
        if self.top is None: return
        self.top.destroy()
        self.top = None

    def mainloop(self, *args, **kwargs):
        if in_idle(): return
        self.top.mainloop(*args, **kwargs)

    def unfreeze_editable(self):
        self.set_paging_button_states()

    def set_paging_button_states(self):
        if self.current_page == -1 or self.current_page == 0:
            self.prev['state'] = 'disabled'
        else:
            self.prev['state'] = 'normal'
        if self.model.is_last_page(self.current_page):
            self.next['state'] = 'disabled'
        else:
            self.next['state'] = 'normal'

    def write_results(self, results):
        self.results_box['state'] = 'normal'
        row = 1
        for each in results:
            self.results_box.insert(str(row) + '.0', each[0] + " " + each[1] + "\n")
            row += 1
        self.results_box['state'] = 'disabled'
开发者ID:gijs,项目名称:nltk,代码行数:104,代码来源:collocations_app.py

示例5: ConcordanceSearchView

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

#.........这里部分代码省略.........
            self.status['text'] = 'Loading ' + selection + '...'
            self.freeze_editable()
            self.model.load_corpus(selection)

    def search(self):
        self.current_page = 0
        self.clear_results_box()
        self.model.reset_results()
        query = self.query_box.get()
        if (len(query.strip()) == 0): return
        self.status['text']  = 'Searching for ' + query
        self.freeze_editable()
        self.model.search(query, self.current_page + 1, )


    def write_results(self, results):
        self.results_box['state'] = 'normal'
        row = 1
        for each in results:
            sent, pos1, pos2 = each[0].strip(), each[1], each[2]
            if len(sent) != 0:
                if (pos1 < self._char_before):
                    sent, pos1, pos2 = self.pad(sent, pos1, pos2)
                sentence = sent[pos1-self._char_before:pos1+self._char_after]
                if not row == len(results):
                    sentence += '\n'
                self.results_box.insert(str(row) + '.0', sentence)
                word_markers, label_markers = self.words_and_labels(sent, pos1, pos2)
                for marker in word_markers: self.results_box.tag_add(self._HIGHLIGHT_WORD_TAG, str(row) + '.' + str(marker[0]), str(row) + '.' + str(marker[1]))
                for marker in label_markers: self.results_box.tag_add(self._HIGHLIGHT_LABEL_TAG, str(row) + '.' + str(marker[0]), str(row) + '.' + str(marker[1]))
                row += 1
        self.results_box['state'] = 'disabled'

    def words_and_labels(self, sentence, pos1, pos2):
        search_exp = sentence[pos1:pos2]
        words, labels = [], []
        labeled_words = search_exp.split(' ')
        index = 0
        for each in labeled_words:
            if each == '':
                index += 1
            else:
                word, label = each.split('/')
                words.append((self._char_before + index, self._char_before + index + len(word)))
                index += len(word) + 1
                labels.append((self._char_before + index, self._char_before + index + len(label)))
                index += len(label)
            index += 1
        return words, labels

    def pad(self, sent, hstart, hend):
        if hstart >= self._char_before:
            return sent, hstart, hend
        d = self._char_before - hstart
        sent = ''.join([' '] * d) + sent
        return sent, hstart + d, hend + d

    def destroy(self, *e):
        if self.top is None: return
        self.top.destroy()
        self.top = None

    def clear_all(self):
        self.query_box.delete(0, END)
        self.model.reset_query()
        self.clear_results_box()

    def clear_results_box(self):
        self.results_box['state'] = 'normal'
        self.results_box.delete("1.0", END)
        self.results_box['state'] = 'disabled'

    def freeze_editable(self):
        self.query_box['state'] = 'disabled'
        self.search_button['state'] = 'disabled'
        self.prev['state'] = 'disabled'
        self.next['state'] = 'disabled'

    def unfreeze_editable(self):
        self.query_box['state'] = 'normal'
        self.search_button['state'] = 'normal'
        self.set_paging_button_states()

    def set_paging_button_states(self):
        if self.current_page == 0 or self.current_page == 1:
            self.prev['state'] = 'disabled'
        else:
            self.prev['state'] = 'normal'
        if self.model.has_more_pages(self.current_page):
            self.next['state'] = 'normal'
        else:
            self.next['state'] = 'disabled'

    def fire_event(self, event):
        #Firing an event so that rendering of widgets happen in the mainloop thread
        self.top.event_generate(event, when='tail')

    def mainloop(self, *args, **kwargs):
        if in_idle(): return
        self.top.mainloop(*args, **kwargs)
开发者ID:Joselin,项目名称:nltk,代码行数:104,代码来源:concordance_app.py


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