Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter在执行到达最后一行后更新第二个应用程序窗口_Python_Tkinter - Fatal编程技术网

Python Tkinter在执行到达最后一行后更新第二个应用程序窗口

Python Tkinter在执行到达最后一行后更新第二个应用程序窗口,python,tkinter,Python,Tkinter,我是Tkinter的新手,我面临着在第二个窗口中更新列表框的问题。 问题是,只有在执行到最后一行而不是在中间时才更新辅助窗口中的ListBox。 起初,在执行到达最后一行后,次窗口弹出,但使用了app.lift()函数lift it,但没有更新 以下是简短的代码片段: class Demo: def m1(LB1): for i in range(10): #rest of code LB1.insert(END,i)

我是Tkinter的新手,我面临着在第二个窗口中更新列表框的问题。 问题是,只有在执行到最后一行而不是在中间时才更新辅助窗口中的ListBox。

起初,在执行到达最后一行后,次窗口弹出,但使用了app.lift()函数lift it,但没有更新

以下是简短的代码片段:

class Demo:
    def m1(LB1):
        for i in range(10):
            #rest of code
            LB1.insert(END,i) 


def f1():
    app2 = Tk()
    app2.title("PROCESSING")
    app2.geometry("350x50")
    app2.lift()
    LB1 = Listbox(app2, height=25, width=100)
    obj = Demo()
    obj.m1(LB1)


def main():
    app = Tk()
    app.title("APP")
    #rest of code
    b1 = Button(app, text="start", height=1, width=80, command=f1)


if __name__ == '__main__':
    main()
提前谢谢

使用了LB1.update()来更新列表框,而不是整个应用程序,它实际上在每次迭代中都会更新列表框

解决方案:

def m1(LB1):
        for i in range(10):
            #rest of code
            LB1.insert(END,i)
            LB1.update()   #this will update the listbox

在这里,我编写了一些代码,希望它能有所帮助(我也有点困惑,你的意思是它不更新,比如它显示一个空的列表框或什么?),我也没有在注释中提到它,但这并不是真正创建类的方式:

从tkinter导入Tk、顶层、按钮、列表框
def second():
顶层=顶层(根)
顶部。聚焦力()
列表框=列表框(顶部)
listbox.pack()
对于范围(10)内的i:
listbox.insert('end',i)
root=Tk()
按钮(root,text='Open',command=second).pack()
root.mainloop()

顺便说一句,代码在完成插入或其他操作后仍然会显示列表框,但它发生得非常快(我尝试了10000个条目(虽然只是数字,但几乎是立即发生的))。

app2=Tk()
更改为
app2=Toplevel()
@TheLizzard感谢您的回复…..已尝试,但未更新bro@TheLizzard已找到app2.update(),但为更新列表框更新整个应用程序是否有效通常使用
.update()
不是一个好做法,因为它可能会导致问题,因此最好使用
.after()
tho从效率的角度来看,它肯定不会引起问题(我只是和我的测试一样确定,测试也没有包括很多东西,但是大约有500个窗口在for循环中加载一个标签时打开得非常顺利,
update()
ing但是正如我说的,你不应该使用
.update()
同样,该类似乎有点毫无意义,它最好只是一个函数。感谢这段代码,但我的主要问题是lostbox应该随着每个条目更新,所以上层再次解决了这个问题,谢谢您的时间!!!