Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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_Performance_Tkinter - Fatal编程技术网

Python Tkinter代码有时运行缓慢,有时运行快速

Python Tkinter代码有时运行缓慢,有时运行快速,python,performance,tkinter,Python,Performance,Tkinter,只是提醒一下,我对特金特还比较陌生 我正在研究一个TKTETE GUI,它被用来与C++编写并运行一个独立的程序,进行一些实验。GUI允许用户设置所有实验,然后运行实验,并在实验发生时监视它们 现在,我正致力于允许用户隐藏或显示GUI的不同部分,这取决于他们当前正在处理的内容。GUI的一个部分由网格中的72个按钮组成,用户可以单击任何按钮,显示一些从JSON文件中提取出来的信息(当程序被加载时,而不是动态地)C++代码用于运行。 问题是,当我试图用72个按钮显示部分时,如果在实验运行之前显示网格

只是提醒一下,我对特金特还比较陌生

我正在研究一个TKTETE GUI,它被用来与C++编写并运行一个独立的程序,进行一些实验。GUI允许用户设置所有实验,然后运行实验,并在实验发生时监视它们

现在,我正致力于允许用户隐藏或显示GUI的不同部分,这取决于他们当前正在处理的内容。GUI的一个部分由网格中的72个按钮组成,用户可以单击任何按钮,显示一些从JSON文件中提取出来的信息(当程序被加载时,而不是动态地)C++代码用于运行。 问题是,当我试图用72个按钮显示部分时,如果在实验运行之前显示网格,则需要很长时间。这很奇怪,因为当实验运行时,网格几乎是瞬间出现的。当它运行缓慢时,GUI可能需要5秒钟来绘制所有72个按钮,我可以看到它们一个接一个地出现

这是两次运行的完全相同的代码。在这两种情况下,它都在同一个线程上运行。实际上,我只是忘记并重新打包了包含按钮的框架,所以这不像每次重新显示部分时我都在创建按钮,我只是在重新打包框架

不幸的是,我真的不知道我应该为这个问题发布的所有代码是什么,因为GUI跨越了数千行代码和许多文件。。。但首先,这里有一段直接代码,显示或隐藏GUI的这一部分:

def showHideControlGrid(self):
    if self.grid_menu_var.get()==0:
        # The grid is currently being shown, so the user wants to hide it.
        self.control.GroupFrames[0].pack_forget()
        self.control.GroupFrames[1].pack_forget()
        if self.grid_menu_var.get() == 0 and self.movements_menu_var.get() == 0:
            #If both the grid and the movement controls are hidden then remove the middle section all together.
            self.midFrame.pack_forget()
    elif self.movements_menu_var.get()==0:
        # The grid is currently hidden, so the user wants to show it. The movement controls are also hidden so we must first repack the entire middle section again.
        self.rightFrame.pack_forget()
        
        self.midFrame.pack(side=LEFT,fill=BOTH,padx=10,pady=10)
        self.control.GroupFrames[0].pack(fill='x')
        self.control.GroupFrames[1].pack(fill='x')

        self.rightFrame.pack(fill=BOTH,padx=10,pady=10)
    else:
        # The grid is currently hidden, so the user wants to show it. The movement controls are currently displayed (meaning the middle section is packed) so we just need to re-pack the grid above the movement controls.
        self.control.GroupFrames[2].pack_forget()

        for w in self.control.GroupFrames:
            w.pack(fill='x')
请注意,GroupFrames[0]和GroupFrames[1]包含网格所在的帧,GroupFrames[2]包含一些移动控件所在的帧。但如果显示移动控件,则它们始终显示在栅格下方

有没有人能理解为什么网格有时绘制得很慢,而另一些绘制得很快