本文整理汇总了Python中tkinter.Listbox方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.Listbox方法的具体用法?Python tkinter.Listbox怎么用?Python tkinter.Listbox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter.Listbox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, root, resource_dir, lang="fr"):
ttk.Frame.__init__(self, root)
self.resource_dir = resource_dir
self._lang = None
langs = os.listdir(os.path.join(self.resource_dir, "master"))
if langs:
self._lang = (lang if lang in langs else langs[0])
self.items = (os.listdir(os.path.join(self.resource_dir, "master", self._lang)) if self._lang else [])
self.items.sort(key=lambda x: x.lower())
max_length = max([len(item) for item in self.items])
self.select_workflow_label = ttk.Label(root, text=u"select workflow:")
#strVar = tkinter.StringVar()
self.masters = tkinter.Listbox(root, width=max_length+1, height=len(self.items))#, textvariable=strVar)
for item in self.items:
self.masters.insert(tkinter.END, item)
示例2: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, control, board):
self.control = control
if self.control.game_mode != 2:
self.can.bind('<Button-1>', self.control.callback)
self.lb = tkinter.Listbox(ChessView.root,selectmode="browse")
self.scr1 = tkinter.Scrollbar(ChessView.root)
self.lb.configure(yscrollcommand=self.scr1.set)
self.scr1['command'] = self.lb.yview
self.scr1.pack(side='right',fill="y")
self.lb.pack(fill="x")
self.lb.bind('<<ListboxSelect>>', self.printList) # Double- <Button-1>
self.board = board
self.last_text_x = 0
self.last_text_y = 0
self.print_text_flag = False
# def start(self):
# tkinter.mainloop()
示例3: showRes
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def showRes (self) :
self.resWindow = tkinter.Toplevel()
self.resWindow.title(self.target['title'])
self.resWindow.resizable(width = 'false', height = 'false')
if self.Tools.isWin() :
self.resWindow.iconbitmap(self.Tools.getRes('biticon.ico'))
self.resWindow.config(background='#444')
self.resFrame = tkinter.Frame(self.resWindow, bd = 0, bg="#444")
self.resFrame.grid(row = 0, column = 0, sticky = '')
btnZone = tkinter.Frame(self.resWindow, bd = 10, bg="#444")
btnZone.grid(row = 1, column = 0, sticky = '')
self.resList = tkinter.Listbox(self.resFrame, height = 8, width = 50, bd = 0, bg="#222", fg = '#ddd',selectbackground = '#116cd6', highlightthickness = 0)
self.resList.grid(row = 0, sticky = '')
viewBtn = tkinter.Button(btnZone, text = '查看连接', width = 10, fg = '#222', highlightbackground = '#444', command = self.__taskShow)
viewBtn.grid(row = 0, column = 0, padx = 5)
watchBtn = tkinter.Button(btnZone, text = '在线观看', width = 10, fg = '#222', highlightbackground = '#444', command = self.__taskWatch)
watchBtn.grid(row = 0, column = 1, padx = 5)
dlBtn = tkinter.Button(btnZone, text = '离线下载', width = 10, fg = '#222', highlightbackground = '#444', command = self.__taskDownload)
dlBtn.grid(row = 0, column = 2, padx = 5)
示例4: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, master=None, callback=None, **kwargs):
"""
Create a FontFamilyListbox.
:param master: master widget
:type master: widget
:param callback: callable object with one argument: the font family name
:type callback: function
:param kwargs: keyword arguments passed to :class:`~ttkwidgets.ScrolledListbox`, in turn passed to :class:`tk.Listbox`
"""
ScrolledListbox.__init__(self, master, compound=tk.RIGHT, **kwargs)
self._callback = callback
font_names = sorted(set(font.families()))
index = 0
self.font_indexes = {}
for name in font_names:
self.listbox.insert(index, name)
self.font_indexes[index] = name
index += 1
self.listbox.bind("<<ListboxSelect>>", self._on_click)
示例5: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, master=None, compound=tk.RIGHT, autohidescrollbar=True, **kwargs):
"""
Create a Listbox with a vertical scrollbar.
:param master: master widget
:type master: widget
:param compound: side for the Scrollbar to be on (:obj:`tk.LEFT` or :obj:`tk.RIGHT`)
:type compound: str
:param autohidescrollbar: whether to use an :class:`~ttkwidgets.AutoHideScrollbar` or a :class:`ttk.Scrollbar`
:type autohidescrollbar: bool
:param kwargs: keyword arguments passed on to the :class:`tk.Listbox` initializer
"""
ttk.Frame.__init__(self, master)
self.columnconfigure(1, weight=1)
self.rowconfigure(0, weight=1)
self.listbox = tk.Listbox(self, **kwargs)
if autohidescrollbar:
self.scrollbar = AutoHideScrollbar(self, orient=tk.VERTICAL, command=self.listbox.yview)
else:
self.scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL, command=self.listbox.yview)
self.config_listbox(yscrollcommand=self.scrollbar.set)
if compound is not tk.LEFT and compound is not tk.RIGHT:
raise ValueError("Invalid compound value passed: {0}".format(compound))
self.__compound = compound
self._grid_widgets()
示例6: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, parent, header, width=10, selectmode=tk.BROWSE):
tk.Frame.__init__(self, parent)
self.parent = parent
self.num_f = len(header)
self.headers = []
self.lbs = []
self.c = 0
self.sel_idxs = []
self.scroll = tk.Scrollbar(self, orient=tk.VERTICAL)
for i in range(0, self.num_f):
self.headers.append(tk.Label(self, text=header[i]))
self.headers[-1].grid(row=0, column=self.c, sticky=tk.EW)
self.lbs.append(tk.Listbox(self, width=width, selectmode=selectmode, yscrollcommand=self.yscroll, bg='white'))
self.lbs[-1].grid(row=1, column=self.c, sticky=tk.EW)
self.lbs[-1].bind("<<ListboxSelect>>", self.select)
self.c += 1
self.scroll.config(command=self.lbs[0].yview)
self.scroll.grid(row=1, column=self.c, sticky=tk.NS)
示例7: iniciaTabPL
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def iniciaTabPL(self):
ttk.Label(self.tabPL, text="Videos disponibles: ",
font=("Arial", 14)).place(x=5,y=10)
self.listPL = Listbox(self.tabPL, height=10, width=66,
font=("Arial", 14), bg='#ABAAAA')
scrollbar = ttk.Scrollbar(self.tabPL,
command=self.listPL.yview, orient=VERTICAL)
self.listPL.config(yscrollcommand=scrollbar.set)
self.listPL.config(selectforeground="#eeeeee",
selectbackground="#89C2DE",
selectborderwidth=1)
self.listPL.place(x=6,y=50)
scrollbar.place(x=723,y=50, height=254)
self.plbvideo = ttk.Button(self.tabPL, text="Ir a descargar video",
command = self.controlador.cargarInfoDesdePL)
self.plbvideo.place(x=30, y=320)
self.plbbvideo = ttk.Button(self.tabPL, text="Descargar playlist video")
self.plbbvideo.place(x=250, y=320)
self.plbbaudio = ttk.Button(self.tabPL, text="Descargar playlist audio")
self.plbbaudio.place(x=500, y=320)
示例8: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, master, items=None, selected=None, command=None, grid=None, align=None, visible=True, enabled=None, multiselect=False, width=None, height=None):
description = "[ListBox] object"
self._multiselect = multiselect
# Create a tk OptionMenu object within this object
mode = EXTENDED if multiselect else BROWSE
# exportselection=0 allows you to select from more than 1 Listbox
tk = Listbox(master.tk, selectmode=mode, exportselection=0)
# Add the items
if items is not None:
for item in items:
tk.insert(END, item)
super(ListBoxWidget, self).__init__(master, tk, description, grid, align, visible, enabled, width, height)
self.events.set_event("<ListBox.ListboxSelect>", "<<ListboxSelect>>", self._command_callback)
# Select the selected items
if selected is not None:
self.value = selected
# The command associated with this combo
self.update_command(command)
示例9: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, text):
tk.Listbox.__init__(
self, master=text, font="SmallEditorFont", activestyle="dotbox", exportselection=False
)
self.text = text
self.completions = []
self.doc_label = tk.Label(
master=text, text="Aaappiiiii", bg="#ffffe0", justify="left", anchor="nw"
)
# Auto indenter will eat up returns, therefore I need to raise the priority
# of this binding
self.text_priority_bindtag = "completable" + str(self.text.winfo_id())
self.text.bindtags((self.text_priority_bindtag,) + self.text.bindtags())
self.text.bind_class(self.text_priority_bindtag, "<Key>", self._on_text_keypress, True)
self.text.bind("<<TextChange>>", self._on_text_change, True) # Assuming TweakableText
# for cases when Listbox gets focus
self.bind("<Escape>", self._close)
self.bind("<Return>", self._insert_current_selection)
self.bind("<Double-Button-1>", self._insert_current_selection)
self._bind_result_event()
示例10: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self):
self.gi = pygeoip.GeoIP("./GeoLiteCity.dat")
# 创建主窗口,用于容纳其它组件
self.root = tkinter.Tk()
# 给主窗口设置标题内容
self.root.title("全球定位ip位置(离线版)")
# 创建一个输入框,并设置尺寸
self.ip_input = tkinter.Entry(self.root,width=30)
# 创建一个回显列表
self.display_info = tkinter.Listbox(self.root, width=50)
# 创建一个查询结果的按钮
self.result_button = tkinter.Button(self.root, command = self.find_position, text = "查询")
# 完成布局
示例11: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, parent, options: List[str],
width: int = 12, height: int = 5,
on_select_callback: callable = None,
selectmode: str = 'browse'):
super().__init__(parent=parent)
self._on_select_callback = on_select_callback
self._values = {}
r = 0
self._lb = tk.Listbox(self, width=width, height=height,
selectmode=selectmode, exportselection=0)
self._lb.grid(row=r, column=0, sticky='ew')
[self._lb.insert('end', option) for option in options]
self._lb.bind('<<ListboxSelect>>', lambda _: self._on_select())
r += 1
clear_label = tk.Label(self, text='clear', fg='blue')
clear_label.grid(row=r, column=0, sticky='ew')
clear_label.bind('<Button-1>', lambda _: self._clear_selected())
示例12: add_word
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def add_word(self):
"""
Adds the word/words to the words array, and refreshes the Listbox
:author: Pablo Sanz Alguacil
"""
new_words = self.entry_words.get().split(" ")
for word in new_words:
self.words.append(word)
self.listbox_words.delete(0, END)
self.listbox_words.insert(END, *self.words)
self.entry_words.delete(0, 'end')
示例13: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, master, **kwargs):
super().__init__(**kwargs)
self.master = master
self.transient(self.master)
self.geometry('500x250')
self.title('Choose font and size')
self.configure(bg=self.master.background)
self.font_list = tk.Listbox(self, exportselection=False)
self.available_fonts = sorted(families())
for family in self.available_fonts:
self.font_list.insert(tk.END, family)
current_selection_index = self.available_fonts.index(self.master.font_family)
if current_selection_index:
self.font_list.select_set(current_selection_index)
self.font_list.see(current_selection_index)
self.size_input = tk.Spinbox(self, from_=0, to=99, value=self.master.font_size)
self.save_button = ttk.Button(self, text="Save", style="editor.TButton", command=self.save)
self.save_button.pack(side=tk.BOTTOM, fill=tk.X, expand=1, padx=40)
self.font_list.pack(side=tk.LEFT, fill=tk.Y, expand=1)
self.size_input.pack(side=tk.BOTTOM, fill=tk.X, expand=1)
示例14: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, master, **kw):
kw['selectmode'] = tk.SINGLE
kw['activestyle'] = 'none'
kw['height'] = '0'
tk.Listbox.__init__(self, master, kw)
self.bind('<Button-1>', self.setCurrent)
self.bind('<B1-Motion>', self.shiftSelection)
self.curIndex = None
示例15: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Listbox [as 别名]
def __init__(self, master=None, **kwargs):
super().__init__(master)
self.frame = self
self.listbox = tk.Listbox(self, **kwargs)
self.xscrollbar = TkUtil.Scrollbar.Scrollbar(self,
command=self.listbox.xview, orient=tk.HORIZONTAL)
self.yscrollbar = TkUtil.Scrollbar.Scrollbar(self,
command=self.listbox.yview, orient=tk.VERTICAL)
self.listbox.configure(yscrollcommand=self.yscrollbar.set,
xscrollcommand=self.xscrollbar.set)
self.xscrollbar.grid(row=1, column=0, sticky=(tk.W, tk.E))
self.yscrollbar.grid(row=0, column=1, sticky=(tk.N, tk.S))
self.listbox.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.W, tk.E))
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)