• <bdo id='lmrZm'></bdo><ul id='lmrZm'></ul>

    <small id='lmrZm'></small><noframes id='lmrZm'>

    <i id='lmrZm'><tr id='lmrZm'><dt id='lmrZm'><q id='lmrZm'><span id='lmrZm'><b id='lmrZm'><form id='lmrZm'><ins id='lmrZm'></ins><ul id='lmrZm'></ul><sub id='lmrZm'></sub></form><legend id='lmrZm'></legend><bdo id='lmrZm'><pre id='lmrZm'><center id='lmrZm'></center></pre></bdo></b><th id='lmrZm'></th></span></q></dt></tr></i><div id='lmrZm'><tfoot id='lmrZm'></tfoot><dl id='lmrZm'><fieldset id='lmrZm'></fieldset></dl></div>
    <tfoot id='lmrZm'></tfoot>

  1. <legend id='lmrZm'><style id='lmrZm'><dir id='lmrZm'><q id='lmrZm'></q></dir></style></legend>
    1. 如何在 Tkinter 列表框中插入时添加自动滚动?

      How to add Autoscroll on insert in Tkinter Listbox?(如何在 Tkinter 列表框中插入时添加自动滚动?)

        <small id='aQhP3'></small><noframes id='aQhP3'>

            • <bdo id='aQhP3'></bdo><ul id='aQhP3'></ul>
              <legend id='aQhP3'><style id='aQhP3'><dir id='aQhP3'><q id='aQhP3'></q></dir></style></legend>

                <tfoot id='aQhP3'></tfoot>

                  <tbody id='aQhP3'></tbody>
                <i id='aQhP3'><tr id='aQhP3'><dt id='aQhP3'><q id='aQhP3'><span id='aQhP3'><b id='aQhP3'><form id='aQhP3'><ins id='aQhP3'></ins><ul id='aQhP3'></ul><sub id='aQhP3'></sub></form><legend id='aQhP3'></legend><bdo id='aQhP3'><pre id='aQhP3'><center id='aQhP3'></center></pre></bdo></b><th id='aQhP3'></th></span></q></dt></tr></i><div id='aQhP3'><tfoot id='aQhP3'></tfoot><dl id='aQhP3'><fieldset id='aQhP3'></fieldset></dl></div>
                本文介绍了如何在 Tkinter 列表框中插入时添加自动滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用列表框(带有滚动条)进行日志记录:

                I'm using a listbox (with scrollbar) for logging:

                self.listbox_log = Tkinter.Listbox(root, height = 5, width = 0,)
                self.scrollbar_log = Tkinter.Scrollbar(root,)
                
                self.listbox_log.configure(yscrollcommand = self.scrollbar_log.set)
                self.scrollbar_log.configure(command = self.listbox_log.yview)
                

                现在,当我这样做时:

                Now, when I do:

                self.listbox_log.insert(END,str)
                

                我希望选择插入的元素.我试过了:

                I want the inserted element to be selected. I've tried:

                self.listbox_log.selection_anchor(END)
                

                但这不起作用...请提出解决方案...

                but that doesn't work... Please suggest a solution...

                推荐答案

                AFAIK ScrollBar 小部件没有自动滚动功能,但可以通过调用 listBox 轻松实现yview() 方法在您插入新项目后.如果您需要选择新项目,那么您也可以使用 listboxselect_set 方法手动完成.

                AFAIK the ScrollBar widget doesn't have an auto-scroll feature, but it can be easily implemented by calling the listBox's yview() method after you insert a new item. If you need the new item to be selected then you can do that manually too using the listbox's select_set method.

                from Tkinter import *
                
                class AutoScrollListBox_demo:
                    def __init__(self, master):
                        frame = Frame(master, width=500, height=400, bd=1)
                        frame.pack()
                
                        self.listbox_log = Listbox(frame, height=4)
                        self.scrollbar_log = Scrollbar(frame) 
                
                        self.scrollbar_log.pack(side=RIGHT, fill=Y)
                        self.listbox_log.pack(side=LEFT,fill=Y) 
                
                        self.listbox_log.configure(yscrollcommand = self.scrollbar_log.set)
                        self.scrollbar_log.configure(command = self.listbox_log.yview)
                
                        b = Button(text="Add", command=self.onAdd)
                        b.pack()
                
                        #Just to show unique items in the list
                        self.item_num = 0
                
                    def onAdd(self):
                        self.listbox_log.insert(END, "test %s" %(str(self.item_num)))       #Insert a new item at the end of the list
                
                        self.listbox_log.select_clear(self.listbox_log.size() - 2)   #Clear the current selected item     
                        self.listbox_log.select_set(END)                             #Select the new item
                        self.listbox_log.yview(END)                                  #Set the scrollbar to the end of the listbox
                
                        self.item_num += 1
                
                
                root = Tk()
                all = AutoScrollListBox_demo(root)
                root.title('AutoScroll ListBox Demo')
                root.mainloop()
                

                这篇关于如何在 Tkinter 列表框中插入时添加自动滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                env: python: No such file or directory(env: python: 没有这样的文件或目录)
                How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                <tfoot id='DmJ97'></tfoot>
              1. <legend id='DmJ97'><style id='DmJ97'><dir id='DmJ97'><q id='DmJ97'></q></dir></style></legend>
                <i id='DmJ97'><tr id='DmJ97'><dt id='DmJ97'><q id='DmJ97'><span id='DmJ97'><b id='DmJ97'><form id='DmJ97'><ins id='DmJ97'></ins><ul id='DmJ97'></ul><sub id='DmJ97'></sub></form><legend id='DmJ97'></legend><bdo id='DmJ97'><pre id='DmJ97'><center id='DmJ97'></center></pre></bdo></b><th id='DmJ97'></th></span></q></dt></tr></i><div id='DmJ97'><tfoot id='DmJ97'></tfoot><dl id='DmJ97'><fieldset id='DmJ97'></fieldset></dl></div>

                      <tbody id='DmJ97'></tbody>

                      <bdo id='DmJ97'></bdo><ul id='DmJ97'></ul>
                        • <small id='DmJ97'></small><noframes id='DmJ97'>