本文整理汇总了Python中tkinter.Listbox.yview方法的典型用法代码示例。如果您正苦于以下问题:Python Listbox.yview方法的具体用法?Python Listbox.yview怎么用?Python Listbox.yview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Listbox
的用法示例。
在下文中一共展示了Listbox.yview方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Searcher
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import yview [as 别名]
class Searcher(Frame):
""" Keyword Searcher
This is a very simple python program, which is designed for finding specified key-word
in files. Just for fun!
"""
def __init__(self, master=None, cnf={}, **kwargs):
super(Searcher, self).__init__(master, cnf, **kwargs)
self._root_path_var = StringVar()
self._keyword_var = StringVar(self)
self._listbox = None
self._result_queue = None
self.pack(fill=BOTH, expand=YES, padx=5, pady=5)
self.make_widgets()
self._consumer()
# config for main window
self.master.title('Keyword Searcher')
def make_widgets(self):
frm1 = Frame(self)
frm1.pack(side=TOP, fill=X)
Entry(frm1, textvariable=self._root_path_var, font=DEFAULT_FONT).pack(side=LEFT, fill=X, expand=YES)
Button(frm1, text='Add directory', font=DEFAULT_FONT,
command=lambda: self._root_path_var.set(askdirectory(title='Add directory'))).pack(side=RIGHT)
frm2 = Frame(self)
frm2.pack(side=TOP, fill=X)
keyword_ent = Entry(frm2, textvariable=self._keyword_var, font=DEFAULT_FONT)
keyword_ent.pack(side=LEFT, fill=X, expand=YES)
Button(frm2, text='Find', font=DEFAULT_FONT, command=self.find).pack(side=RIGHT)
vs = Scrollbar(self)
hs = Scrollbar(self)
self._listbox = Listbox(self)
vs.pack(side=RIGHT, fill=Y)
vs.config(command=self._listbox.yview)
hs.pack(side=BOTTOM, fill=X)
hs.config(command=self._listbox.xview, orient='horizontal')
self._listbox.config(yscrollcommand=vs.set, xscrollcommand=hs.set,
font=DEFAULT_FONT)
self._listbox.pack(fill=BOTH, expand=YES)
self._listbox.bind('<Double-1>', self._navigate_to)
def find(self):
self._result_queue = queue.Queue()
self._listbox.delete('0', 'end')
Thread(target=self._find, args=(self._root_path_var.get(),
self._keyword_var.get()), daemon=True).start()
def _find(self, path, keyword):
if not os.path.exists(path):
return None
for this_dir, sub_dirs, files in os.walk(path):
for file in files:
file_type = guess_type(file)[0]
if file_type and 'text' in file_type:
fp = os.path.join(this_dir, file)
self._result_queue.put(fp) if keyword in open(fp).read() else None
def _consumer(self):
if self._result_queue:
try:
fp = self._result_queue.get(block=False)
except queue.Empty:
pass
else:
self._listbox.insert('end', fp)
# auto scroll.
self._listbox.yview('end')
self.after(100, self._consumer)
def _navigate_to(self, event):
"""
Only works on Ubuntu platform currently.
Double click to navigate to selected path.
It's a very convenient function.
:return: None
"""
print(event)
# get active item from listbox
path = self._listbox.get('active')
print(path)
# open nautilus with param path, before that, check your platform.
if 'ubuntu' in (os.popen('uname -a').read()).lower():
os.system('/usr/bin/nautilus {}'.format(path))
else:
pass
示例2: Example
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import yview [as 别名]
#.........这里部分代码省略.........
lbl3 = Label(area3, text="Class")
self.listbox3 = Listbox(
area3, yscrollcommand=self.scrollbar.set, font=fontb, relief=FLAT, highlightthickness=0, activestyle="none"
)
lbl3.pack(side=TOP)
self.listbox3.pack(side=BOTTOM, fill=Y, expand=1)
# area4
area4 = Frame(area)
area4.pack(side=LEFT, fill=Y)
lbl4 = Label(area4, text="Race")
self.listbox4 = Listbox(
area4, yscrollcommand=self.scrollbar.set, font=fontb, relief=FLAT, highlightthickness=0, activestyle="none"
)
lbl4.pack(side=TOP)
self.listbox4.pack(side=BOTTOM, fill=Y, expand=1)
# area3
area5 = Frame(area)
area5.pack(side=LEFT, fill=Y)
lbl5 = Label(area5, text="Zone")
self.listbox5 = Listbox(
area5, yscrollcommand=self.scrollbar.set, font=fontb, relief=FLAT, highlightthickness=0, activestyle="none"
)
lbl5.pack(side=TOP)
self.listbox5.pack(side=BOTTOM, fill=Y, expand=1)
self.pack(fill=BOTH, expand=1)
# config-scrollbar
self.scrollbar.config(command=self.yview)
self.scrollbar2["command"] = self.listboxLogs.yview
# bindeos de acciones
self.listbox.bind("<<ListboxSelect>>", self.onSelect)
self.listbox.bind("<MouseWheel>", self.onTest)
self.listbox2.bind("<<ListboxSelect>>", self.onSelect)
self.listbox2.bind("<MouseWheel>", self.onTest)
self.listbox3.bind("<<ListboxSelect>>", self.onSelect)
self.listbox3.bind("<MouseWheel>", self.onTest)
self.listbox4.bind("<<ListboxSelect>>", self.onSelect)
self.listbox4.bind("<MouseWheel>", self.onTest)
self.listbox5.bind("<<ListboxSelect>>", self.onSelect)
self.listbox5.bind("<MouseWheel>", self.onTest)
self.listboxLogs.bind("<<ListboxSelect>>", self.onSelectPlayer)
# mostrar la barra de scroll
def yview(self, *args):
self.listbox.yview(*args)
self.listbox2.yview(*args)
self.listbox3.yview(*args)
self.listbox4.yview(*args)
self.listbox5.yview(*args)
# accion de la rueda del raton
def onTest(self, val):
return "break"
# seleccionar un elementos de una listbox
def onSelect(self, val):
try:
if self.ant != None:
self.listbox.itemconfig(self.ant, background="#FFFFFF")
示例3: LintGui
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import yview [as 别名]
class LintGui(object):
"""Build and control a window to interact with pylint"""
def __init__(self, root=None):
"""init"""
self.root = root or Tk()
self.root.title('Pylint')
#reporter
self.reporter = None
#message queue for output from reporter
self.msg_queue = queue.Queue()
self.msgs = []
self.visible_msgs = []
self.filenames = []
self.rating = StringVar()
self.tabs = {}
self.report_stream = BasicStream(self)
#gui objects
self.lb_messages = None
self.showhistory = None
self.results = None
self.btnRun = None
self.information_box = None
self.convention_box = None
self.refactor_box = None
self.warning_box = None
self.error_box = None
self.fatal_box = None
self.txtModule = None
self.status = None
self.msg_type_dict = None
self.init_gui()
def init_gui(self):
"""init helper"""
#setting up frames
top_frame = Frame(self.root)
mid_frame = Frame(self.root)
radio_frame = Frame(self.root)
res_frame = Frame(self.root)
msg_frame = Frame(self.root)
check_frame = Frame(self.root)
history_frame = Frame(self.root)
btn_frame = Frame(self.root)
rating_frame = Frame(self.root)
top_frame.pack(side=TOP, fill=X)
mid_frame.pack(side=TOP, fill=X)
history_frame.pack(side=TOP, fill=BOTH, expand=True)
radio_frame.pack(side=TOP, fill=BOTH, expand=True)
rating_frame.pack(side=TOP, fill=BOTH, expand=True)
res_frame.pack(side=TOP, fill=BOTH, expand=True)
check_frame.pack(side=TOP, fill=BOTH, expand=True)
msg_frame.pack(side=TOP, fill=BOTH, expand=True)
btn_frame.pack(side=TOP, fill=X)
# Binding F5 application-wide to run lint
self.root.bind('<F5>', self.run_lint)
#Message ListBox
rightscrollbar = Scrollbar(msg_frame)
rightscrollbar.pack(side=RIGHT, fill=Y)
bottomscrollbar = Scrollbar(msg_frame, orient=HORIZONTAL)
bottomscrollbar.pack(side=BOTTOM, fill=X)
self.lb_messages = Listbox(msg_frame,
yscrollcommand=rightscrollbar.set,
xscrollcommand=bottomscrollbar.set,
bg="white")
self.lb_messages.bind("<Double-Button-1>", self.show_sourcefile)
self.lb_messages.pack(expand=True, fill=BOTH)
rightscrollbar.config(command=self.lb_messages.yview)
bottomscrollbar.config(command=self.lb_messages.xview)
#History ListBoxes
rightscrollbar2 = Scrollbar(history_frame)
rightscrollbar2.pack(side=RIGHT, fill=Y)
bottomscrollbar2 = Scrollbar(history_frame, orient=HORIZONTAL)
bottomscrollbar2.pack(side=BOTTOM, fill=X)
self.showhistory = Listbox(history_frame,
yscrollcommand=rightscrollbar2.set,
xscrollcommand=bottomscrollbar2.set,
bg="white")
self.showhistory.pack(expand=True, fill=BOTH)
rightscrollbar2.config(command=self.showhistory.yview)
bottomscrollbar2.config(command=self.showhistory.xview)
self.showhistory.bind('<Double-Button-1>', self.select_recent_file)
self.set_history_window()
#status bar
self.status = Label(self.root, text="", bd=1, relief=SUNKEN, anchor=W)
self.status.pack(side=BOTTOM, fill=X)
#labelbl_ratingls
lbl_rating_label = Label(rating_frame, text='Rating:')
lbl_rating_label.pack(side=LEFT)
lbl_rating = Label(rating_frame, textvariable=self.rating)
lbl_rating.pack(side=LEFT)
Label(mid_frame, text='Recently Used:').pack(side=LEFT)
Label(top_frame, text='Module or package').pack(side=LEFT)
#file textbox
#.........这里部分代码省略.........
示例4: GetKeysDialog
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import yview [as 别名]
#.........这里部分代码省略.........
self.frame_controls_basic = Frame(frame)
self.frame_controls_basic.grid(row=1, column=0, sticky='nsew', padx=5)
# Basic entry modifiers.
self.modifier_checkbuttons = {}
column = 0
for modifier, variable in zip(self.modifiers, self.modifier_vars):
label = self.modifier_label.get(modifier, modifier)
check = Checkbutton(self.frame_controls_basic,
command=self.build_key_string, text=label,
variable=variable, onvalue=modifier, offvalue='')
check.grid(row=0, column=column, padx=2, sticky='w')
self.modifier_checkbuttons[modifier] = check
column += 1
# Basic entry help text.
help_basic = Label(self.frame_controls_basic, justify='left',
text="Select the desired modifier keys\n"+
"above, and the final key from the\n"+
"list on the right.\n\n" +
"Use upper case Symbols when using\n" +
"the Shift modifier. (Letters will be\n" +
"converted automatically.)")
help_basic.grid(row=1, column=0, columnspan=4, padx=2, sticky='w')
# Basic entry key list.
self.list_keys_final = Listbox(self.frame_controls_basic, width=15,
height=10, selectmode='single')
self.list_keys_final.insert('end', *AVAILABLE_KEYS)
self.list_keys_final.bind('<ButtonRelease-1>', self.final_key_selected)
self.list_keys_final.grid(row=0, column=4, rowspan=4, sticky='ns')
scroll_keys_final = Scrollbar(self.frame_controls_basic,
orient='vertical',
command=self.list_keys_final.yview)
self.list_keys_final.config(yscrollcommand=scroll_keys_final.set)
scroll_keys_final.grid(row=0, column=5, rowspan=4, sticky='ns')
self.button_clear = Button(self.frame_controls_basic,
text='Clear Keys',
command=self.clear_key_seq)
self.button_clear.grid(row=2, column=0, columnspan=4)
# Advanced entry key sequence.
self.frame_keyseq_advanced = Frame(frame, name='keyseq_advanced')
self.frame_keyseq_advanced.grid(row=0, column=0, sticky='nsew',
padx=5, pady=5)
advanced_title = Label(self.frame_keyseq_advanced, justify='left',
text=f"Enter new binding(s) for '{self.action}' :\n" +
"(These bindings will not be checked for validity!)")
advanced_title.pack(anchor='w')
self.advanced_keys = Entry(self.frame_keyseq_advanced,
textvariable=self.key_string)
self.advanced_keys.pack(fill='x')
# Advanced entry help text.
self.frame_help_advanced = Frame(frame)
self.frame_help_advanced.grid(row=1, column=0, sticky='nsew', padx=5)
help_advanced = Label(self.frame_help_advanced, justify='left',
text="Key bindings are specified using Tkinter keysyms as\n"+
"in these samples: <Control-f>, <Shift-F2>, <F12>,\n"
"<Control-space>, <Meta-less>, <Control-Alt-Shift-X>.\n"
"Upper case is used when the Shift modifier is present!\n\n" +
"'Emacs style' multi-keystroke bindings are specified as\n" +
"follows: <Control-x><Control-y>, where the first key\n" +
"is the 'do-nothing' keybinding.\n\n" +
"Multiple separate bindings for one action should be\n"+
"separated by a space, eg., <Alt-v> <Meta-v>." )
示例5: consoleScreen
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import yview [as 别名]
class consoleScreen(Screen):
def __init__(self, runner):
self.runner = runner
self.messages = {}
Screen.destroy()
Screen.reinit()
super().__init__()
Screen.title("NaOH: PocketMine-MP Console")
# GUI initialization
fstframe = Frame(Screen.root)
fstframe.grid(row=0, rowspan=1, columnspan=8)
sndframe = Frame(Screen.root)
sndframe.grid(row=0, rowspan=1, column=8, columnspan=2)
self.scrollbar = Scrollbar(fstframe)
self.listbox = Listbox(fstframe, yscrollcommand=self.scrollbar.set, width=120, height=25)
self.listbox.grid(row=0, column=0, rowspan=1, columnspan=7, sticky='nswe')
self.scrollbar.config(command=self.listbox.yview)
self.scrollbar.grid(row=0, column=7, rowspan=1, sticky='nse')
self.scrolllock = False
Button(fstframe, text='나가기 (주의: 강제 종료됩니다)', command=self.runner.killAll).grid(row=1, column=0, sticky='nwse')
self.slbutton = Button(fstframe, text='ScrollLock Off', command=self.togglesl)
self.slbutton.grid(row=1, column=1, sticky='new')
Label(fstframe, text='명령어: /', justify='right').grid(row=1, column=2)
self.cmdentry = Entry(fstframe)
self.cmdentry.bind('<Return>', self.put_cmd)
self.cmdentry.grid(row=1, column=3, columnspan=5, sticky='nwe')
fstframe.rowconfigure(1, weight=1)
fstframe.columnconfigure(3, weight=1)
fstframe.columnconfigure(4, weight=20)
sndframe.rowconfigure(0, weight=1)
Button(sndframe, text='서버 상태', command=lambda: statusScreen(self)).grid(row=0, sticky='n')
Button(sndframe, text='설정 편집', command=lambda: propertiesScreen(self.runner.workdir + sep + 'server.properties')).grid(row=1, sticky='n')
Button(sndframe, text='덤프 삭제', command=self.removeDumps).grid(row=2, sticky='n')
self.cmdentry.focus()
Screen.root.focus_force()
# GUI initialization done
self.thread = threading.Thread(target=lambda: asyncStream(self)).start()
Screen.root.protocol("WM_DELETE_WINDOW", self.runner.killAll)
Screen.root.mainloop()
try:
Screen.root.destroy()
except:
self.runner.killAll()
def put_cmd(self, event):
# self.runner.pipe.communicate(('/' + self.cmdentry.get() + '\n').encode(), timeout=0)
write(self.runner.pipe.stdin.fileno(), (self.cmdentry.get() + '\n').encode('utf-8'))
self.cmdentry.delete(0, 'end')
def togglesl(self):
if self.scrolllock:
self.scrolllock = False
self.slbutton['text'] = 'ScrollLock Off'
else:
self.scrolllock = True
self.slbutton['text'] = 'ScrollLock On'
def removeDumps(self):
files = [f for f in listdir(self.runner.workdir) if path.isfile(path.join(self.runner.workdir, f)) and f[0:9] =='CrashDump']
for f in files:
unlink(path.join(self.runner.workdir, f))
self.listbox.insert('end', '')
if len(files) > 0:
self.listbox.insert('end', '** %d개의 크래시 덤프들이 삭제되었습니다' % len(files))
else:
self.listbox.insert('end', '** 삭제할 크래시 덤프가 없습니다.')
self.listbox.insert('end', '')
if not self.scrolllock:
self.listbox.yview('end')