本文整理汇总了Python中tkinter.Listbox.selection_clear方法的典型用法代码示例。如果您正苦于以下问题:Python Listbox.selection_clear方法的具体用法?Python Listbox.selection_clear怎么用?Python Listbox.selection_clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Listbox
的用法示例。
在下文中一共展示了Listbox.selection_clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RecursiveDescentApp
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import selection_clear [as 别名]
#.........这里部分代码省略.........
#self._autostep_button['text'] = 'Autostep'
self._autostep = 0
# Make sure to stop auto-stepping if we get any user input.
def step(self, *e): self._autostep = 0; self._step()
def match(self, *e): self._autostep = 0; self._match()
def expand(self, *e): self._autostep = 0; self._expand()
def backtrack(self, *e): self._autostep = 0; self._backtrack()
def _step(self):
if self._animating_lock: return
# Try expanding, matching, and backtracking (in that order)
if self._expand(): pass
elif self._parser.untried_match() and self._match(): pass
elif self._backtrack(): pass
else:
self._lastoper1['text'] = 'Finished'
self._lastoper2['text'] = ''
self._autostep = 0
# Check if we just completed a parse.
if self._parser.currently_complete():
self._autostep = 0
self._lastoper2['text'] += ' [COMPLETE PARSE]'
def _expand(self, *e):
if self._animating_lock: return
old_frontier = self._parser.frontier()
rv = self._parser.expand()
if rv is not None:
self._lastoper1['text'] = 'Expand:'
self._lastoper2['text'] = rv
self._prodlist.selection_clear(0, 'end')
index = self._productions.index(rv)
self._prodlist.selection_set(index)
self._animate_expand(old_frontier[0])
return 1
else:
self._lastoper1['text'] = 'Expand:'
self._lastoper2['text'] = '(all expansions tried)'
return 0
def _match(self, *e):
if self._animating_lock: return
old_frontier = self._parser.frontier()
rv = self._parser.match()
if rv is not None:
self._lastoper1['text'] = 'Match:'
self._lastoper2['text'] = rv
self._animate_match(old_frontier[0])
return 1
else:
self._lastoper1['text'] = 'Match:'
self._lastoper2['text'] = '(failed)'
return 0
def _backtrack(self, *e):
if self._animating_lock: return
if self._parser.backtrack():
elt = self._parser.tree()
for i in self._parser.frontier()[0]:
elt = elt[i]
self._lastoper1['text'] = 'Backtrack'
self._lastoper2['text'] = ''
if isinstance(elt, Tree):
示例2: ShiftReduceApp
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import selection_clear [as 别名]
#.........这里部分代码省略.........
# Move the remaining text to the correct location (keep it
# right-justified, when possible); and move the remaining text
# label, if necessary.
stackx = max(stackx, self._stacklabel.width()+25)
rlabelwidth = self._rtextlabel.width()+10
if stackx >= cx2-max(rtextwidth, rlabelwidth):
cx2 = stackx + max(rtextwidth, rlabelwidth)
for rtextwidget in self._rtextwidgets:
rtextwidget.move(4+cx2-rtextwidth, 0)
self._rtextlabel.move(cx2-self._rtextlabel.bbox()[2]-5, 0)
midx = (stackx + cx2-max(rtextwidth, rlabelwidth))/2
self._canvas.coords(self._stacktop, midx, 0, midx, 5000)
(x1, y1, x2, y2) = self._stacklabel.bbox()
# Set up binding to allow them to shift a token by dragging it.
if len(self._rtextwidgets) > 0:
def drag_shift(widget, midx=midx, self=self):
if widget.bbox()[0] < midx: self.shift()
else: self._redraw()
self._rtextwidgets[0].bind_drag(drag_shift)
self._rtextwidgets[0].bind_click(self.shift)
# Draw the stack top.
self._highlight_productions()
def _draw_stack_top(self, widget):
# hack..
midx = widget.bbox()[2]+50
self._canvas.coords(self._stacktop, midx, 0, midx, 5000)
def _highlight_productions(self):
# Highlight the productions that can be reduced.
self._prodlist.selection_clear(0, 'end')
for prod in self._parser.reducible_productions():
index = self._productions.index(prod)
self._prodlist.selection_set(index)
#########################################
## Button Callbacks
#########################################
def destroy(self, *e):
if self._top is None: return
self._top.destroy()
self._top = None
def reset(self, *e):
self._parser.initialize(self._sent)
self._lastoper1['text'] = 'Reset App'
self._lastoper2['text'] = ''
self._redraw()
def step(self, *e):
if self.reduce(): return True
elif self.shift(): return True
else:
if list(self._parser.parses()):
self._lastoper1['text'] = 'Finished:'
self._lastoper2['text'] = 'Success'
else:
self._lastoper1['text'] = 'Finished:'
self._lastoper2['text'] = 'Failure'
def shift(self, *e):
if self._animating_lock: return
示例3: ListboxVidget
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import selection_clear [as 别名]
#.........这里部分代码省略.........
# If the listbox is changing
if self._is_changing:
# Raise error
raise ListboxVidget.CircularCallError()
# If the listbox is not changing.
# Set changing flag on
self._is_changing = True
# Get old active index
old_indexcur = self._indexcur
# Set resetting flag on if new and old indexes are equal
self._is_resetting = (index == old_indexcur)
# If notify events
if notify:
# Notify pre-change event
self.handler_notify(self.ITEMCUR_CHANGE_SOON, notify_arg)
# If old active index is valid
if self.index_is_valid(old_indexcur):
# Set old active item's background color to normal color
self._listbox.itemconfig(old_indexcur, background=self._normal_bg)
# Set old active item's foreground color to normal color
self._listbox.itemconfig(old_indexcur, foreground=self._normal_fg)
# Cache new active index
self._indexcur = index
# Clear listbox widget's selection
self._listbox.selection_clear(0, END)
# Set listbox widget's selection
self._listbox.selection_set(index)
# Set listbox widget's activated index
self._listbox.activate(index)
# If new active index is valid
if index != -1:
# Set new active item's background color to active color
self._listbox.itemconfig(index, background=self._active_bg)
# Set new active item's foreground color to active color
self._listbox.itemconfig(index, foreground=self._active_fg)
# If set focus
if focus:
# Set focus on the listbox widget
self._listbox.focus_set()
# If new active index is valid
if index != -1:
# Make the active item visible
self._listbox.see(index)
# If notify events
if notify:
# Notify post-change event
self.handler_notify(self.ITEMCUR_CHANGE_DONE, notify_arg)
# Set resetting flag off
self._is_resetting = False
示例4: DrtGlueDemo
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import selection_clear [as 别名]
#.........这里部分代码省略.........
Message(message=ABOUT, title=TITLE).show()
except:
ShowText(self._top, TITLE, ABOUT)
def postscript(self, *e):
self._autostep = 0
self._cframe.print_to_file()
def mainloop(self, *args, **kwargs):
"""
Enter the Tkinter mainloop. This function must be called if
this demo is created from a non-interactive program (e.g.
from a secript); otherwise, the demo will close as soon as
the script completes.
"""
if in_idle():
return
self._top.mainloop(*args, **kwargs)
def resize(self, size=None):
if size is not None:
self._size.set(size)
size = self._size.get()
self._font.configure(size=-(abs(size)))
self._boldfont.configure(size=-(abs(size)))
self._sysfont.configure(size=-(abs(size)))
self._bigfont.configure(size=-(abs(size + 2)))
self._redraw()
def _toggle_remove_duplicates(self):
self._glue.remove_duplicates = not self._glue.remove_duplicates
self._exampleList.selection_clear(0, "end")
self._readings = []
self._populate_readingListbox()
self._readingCache = [None for ex in self._examples]
self._curExample = -1
self._error = None
self._drs = None
self._redraw()
def _exampleList_select(self, event):
selection = self._exampleList.curselection()
if len(selection) != 1:
return
self._exampleList_store_selection(int(selection[0]))
def _exampleList_store_selection(self, index):
self._curExample = index
example = self._examples[index]
self._exampleList.selection_clear(0, "end")
if example:
cache = self._readingCache[index]
if cache:
if isinstance(cache, list):
self._readings = cache
self._error = None
else:
self._readings = []
self._error = cache
else:
try:
self._readings = self._glue.parse_to_meaning(example)
示例5: AutocompleteEntry
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import selection_clear [as 别名]
class AutocompleteEntry(Entry):
def __init__(self, *args, **kwargs):
Entry.__init__(self, width=100, *args, **kwargs)
self.focus_set()
self.pack()
self.var = self["textvariable"]
if self.var == '':
self.var = self["textvariable"] = StringVar()
self.var.trace('w', self.changed)
self.bind("<Right>", self.selection)
self.bind("<Up>", self.up)
self.bind("<Down>", self.down)
self.bind("<Return>", self.enter)
self.lb_up = False
self.lb = None
def enter(self, event):
print(event)
def changed(self, name, index, mode):
if self.var.get() == '':
if self.lb:
self.lb.destroy()
self.lb_up = False
else:
words = self.comparison()
if words:
if not self.lb_up:
self.lb = Listbox(master=root, width=100)
self.lb.bind("<Double-Button-1>", self.selection)
self.lb.bind("<Right>", self.selection)
self.lb.place(x=self.winfo_x(), y=self.winfo_y()+self.winfo_height())
self.lb_up = True
self.lb.delete(0, END)
for w in words:
self.lb.insert(END,w)
else:
if self.lb_up:
self.lb.destroy()
self.lb_up = False
def selection(self, _):
if self.lb_up:
self.var.set(self.lb.get(ACTIVE))
self.lb.destroy()
self.lb_up = False
self.icursor(END)
def up(self, _):
if self.lb_up:
if self.lb.curselection() == ():
index = '0'
else:
index = self.lb.curselection()[0]
if index != '0':
self.lb.selection_clear(first=index)
index = str(int(index)-1)
self.lb.selection_set(first=index)
self.lb.activate(index)
def down(self, _):
if self.lb_up:
if self.lb.curselection() == ():
index = '0'
else:
index = self.lb.curselection()[0]
if index != END:
self.lb.selection_clear(first=index)
index = str(int(index)+1)
self.lb.selection_set(first=index)
self.lb.activate(index)
def comparison(self):
q = self.var.get()
q = str(q.decode('utf8'))
for hit in searcher.search(qp.parse(q), limit=50):
if hit['author']:
yield '%s. "%s"' % (hit['author'], hit['title'])
else:
yield hit['title']
示例6: TextSelect
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import selection_clear [as 别名]
class TextSelect(Frame):
def __init__(self, client, anchor, items, destroyAnchor=False):
"""
Args:
client: [SelectionClient] The window that text is returned to.
anchor: A window that the text selection popup is created
relative to.
items: [str], items to display in the listbox.
destroyAnchor: [bool] if true, destroy the anchor after
positioning the window.
"""
self.top = Toplevel()
self.anchor = anchor
self.top.overrideredirect(1)
self.top.wm_geometry('+%s+%s' % (anchor.winfo_rootx() + anchor.winfo_x(),
anchor.winfo_rooty() + anchor.winfo_y()
)
)
super(TextSelect, self).__init__(self.top)
self.entry = Entry(self)
self.client = client
self.items = items
self.place(x = 0.5, y = 0.5, height = 100, width = 100)
self.entry.bind('<Return>', self.close)
self.entry.bind('<KeyPress>', self.filter)
self.entry.bind('<Escape>', self.abort)
self.entry.bind('<Up>', self.up)
self.entry.bind('<Down>', self.down)
self.entry.pack()
# Create the list of items.
self.list = Listbox(self)
for item in self.items:
self.list.insert('end', item)
self.list.pack()
self.grid()
self.entry.focus()
# Reposition the select button against the anchor. We defer this
# until after idle so that the anchor has a chance to get rendered.
def reposition(*args):
self.top.wm_geometry('+%s+%s' % (
anchor.winfo_rootx(),
anchor.winfo_rooty())
)
if destroyAnchor:
anchor.destroy()
self.after_idle(reposition)
def close(self, event):
sel = self.list.curselection()
if sel:
item = self.list.get(sel[0])
else:
item = self.entry.get()
# Note that the order of this appears to be significant: destroying
# before selecting leaves the focus in a weird state.
self.client.selected(item)
self.top.destroy()
return 'braek'
def abort(self, event):
self.top.destroy()
self.client.aborted()
return 'break'
def up(self, event):
sel = self.list.curselection()
if not sel:
self.list.selection_set(0)
return 'break'
sel = sel[0]
print('sel is %s size is %s' % (sel, self.list.size()))
if sel > 0:
print('setting selection to %s' % sel)
self.list.selection_clear(sel)
self.list.selection_set(sel - 1)
self.list.see(sel)
return 'break'
def down(self, event):
sel = self.list.curselection()
if not sel:
self.list.selection_set(0)
return 'break'
sel = sel[0]
print('sel is %s size is %s' % (sel, self.list.size()))
if sel < self.list.size() - 1:
print('setting selection to %s' % (sel + 1))
self.list.selection_clear(sel)
self.list.selection_set(sel + 1)
self.list.see(sel)
return 'break'
def filter(self, event):
"""Filter the listbox based on the contents of the entryfield."""
#.........这里部分代码省略.........