本文整理汇总了Python中tkinter.Listbox.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python Listbox.destroy方法的具体用法?Python Listbox.destroy怎么用?Python Listbox.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Listbox
的用法示例。
在下文中一共展示了Listbox.destroy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mjolnir3
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import destroy [as 别名]
class Mjolnir3(KRCCModule):
def __init__(self, root):
super().__init__()
self.root = root
self.exception = None
self.list_string = StringVar()
self.listbox = Listbox(root, listvariable=self.list_string,
font='TkFixedFont', width=300)
self.load()
def establish_connection_and_run(self):
error = None
dots = 0
connection = None
while not self.terminate:
try:
if connection is None:
connection = krpc.connect(name=self.name)
self.run_with_connection(connection)
error = None
dots = 0
except Exception as e:
if error != e.args[0]:
error = e.args[0]
print('\n')
print(traceback.format_exc())
sys.stdout.write('Retrying...\n')
if dots > 80:
dots = 0
sys.stdout.write('\n')
sys.stdout.write('.')
dots += 1
sys.stdout.flush()
time.sleep(1)
if connection is not None:
connection.close()
def run_with_connection(self, connection):
logging.debug('KRPC connection established')
strategy = PreLaunch(connection)
while not self.terminate:
strategy = strategy.update()
self.list_string.set(tuple(strategy.display()))
def run(self):
try:
self.establish_connection_and_run()
self.listbox.destroy()
except RuntimeError:
# Should only happen when KeyboardInterrupt is thrown in the MainThread.
pass
@property
def name(self):
return 'Mjolnir 3'
def load(self):
self.listbox.pack(side=LEFT, fill=BOTH)
示例2: Tenacity2
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import destroy [as 别名]
class Tenacity2(KRCCModule):
def __init__(self, root):
super().__init__()
self.arbitrary_list = [
('bla', random.uniform(0, 500)),
('blub', random.randint(1, 10)),
('hurrz', 'yolo'),
'sploink',
]
self.listbox = Listbox(root)
self.canvas = Canvas(root)
self.load()
def __del__(self):
self.canvas.destroy()
self.listbox.destroy()
def run(self):
while not self.terminate:
pass
def name(self):
return 'Tenacity 2'
def load(self):
for item in self.arbitrary_list:
insert_item = 'error'
if type(item) == type(''):
insert_item = item
elif type(item) == type(()):
key = item[0]
value = '%s' % item[1]
if type(item[1]) == float:
value = '%8.3f' % item[1]
insert_item = '%s: %s' % (key, value)
self.listbox.insert(END, insert_item)
self.listbox.pack(side=LEFT, fill=Y)
self.canvas.pack(side=RIGHT, fill=BOTH, expand=True)
示例3: AutoCompleteEntry
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import destroy [as 别名]
class AutoCompleteEntry(Entry): # pylint: disable=too-many-ancestors
"""
An entry widget with asdf.
"""
def __init__(self, autocomplete_list, *args, **kwargs):
self.autocomplete_list = autocomplete_list
self.list_box_length = kwargs.pop('list_box_length', 8)
self.matches_function = kwargs.pop('matches_function',
self._default_match)
# function to initate_string_var_no_textvariable
self.textvariable = kwargs.get('textvariable', StringVar())
self.list_box = None
super().__init__(*args, **kwargs)
self.config(textvariable=self.textvariable)
self.focus()
self.textvariable.trace('w', self._changed)
@property
def existing_list_box(self):
"""
Check if this instance has its' listbox defined/open.
"""
return self.__dict__.get('list_box', False)
@staticmethod
def _default_match(query, list_entry):
"""
The default match function if none is given during instantiation.
"""
pattern = re.compile(re.escape(query) + '.*', re.IGNORECASE)
return re.match(pattern, list_entry)
def _changed(self, name, index, mode):
"""
Event handler for changes to entry.
"""
print("in _changed")
print(name, index, mode)
if self.textvariable.get(): # not empty string
words = self.__comparison()
if not words:
return self.__delete_existing_list_box()
if not self.existing_list_box:
self.list_box = Listbox(width=self["width"],
height=self.list_box_length)
# looks hacky
self.list_box.place(
x=self.winfo_x(), y=self.winfo_y() + self.winfo_height())
self.list_box.delete(0, END)
for word in words:
self.list_box.insert(END, word)
else:
self.__delete_existing_list_box()
def __delete_existing_list_box(self):
"""
Deletes open listbox.
"""
if self.existing_list_box:
self.list_box.destroy()
# hmmmm
def __comparison(self):
"""
Finds words similar to query. TODO
"""
if len(self.get()) < 3:
return []
ans = [w for w in self.autocomplete_list if
self.matches_function(self.textvariable.get(), w)]
print(ans)
return ans[:5]
示例4: AutocompleteEntry
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import destroy [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']