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
Performance 如何修复CPU峰值?_Performance_Tkinter - Fatal编程技术网

Performance 如何修复CPU峰值?

Performance 如何修复CPU峰值?,performance,tkinter,Performance,Tkinter,我有一个简单的程序,可以无限期地放置3张相邻的图片。当没有其他进程运行时,CPU使用率保持在1%左右。然而,当我打开使用大量CPU的程序(比如我的internet broswer)时,它会导致我的程序在CPU使用率10%到15%之间徘徊。当我关闭浏览器时,我的程序将恢复到1%的使用率。有没有快速解决这个问题的方法?代码如下: from tkinter import * from tkinter import PhotoImage from PIL import Image, ImageTk r

我有一个简单的程序,可以无限期地放置3张相邻的图片。当没有其他进程运行时,CPU使用率保持在1%左右。然而,当我打开使用大量CPU的程序(比如我的internet broswer)时,它会导致我的程序在CPU使用率10%到15%之间徘徊。当我关闭浏览器时,我的程序将恢复到1%的使用率。有没有快速解决这个问题的方法?代码如下:

from tkinter import *
from tkinter import PhotoImage
from PIL import Image, ImageTk

root = Tk()
root.geometry('300x100')

im1=Image.open('c1.jpg')
im2=Image.open('c2.jpg')
im3=Image.open('c3.jpg')
photo1=ImageTk.PhotoImage(im1)
photo2=ImageTk.PhotoImage(im2)
photo3=ImageTk.PhotoImage(im3)

def start(root, L1):
    L1['im'] =photo1
    L2['im'] =photo2
    L3['im'] =photo3

    root.after(10, start, root, L1)

L1=Label(im='')
L1.place(x=0, y=0)
L2=Label(im='')
L2.place(x=100, y=0)
L3=Label(im='')
L3.place(x=200, y=0)

start(root, L1)

root.mainloop()

您真的需要每秒将标签设置为相同的图像100次吗?这是一个简单的例子,我写这段代码是为了表达我在一个更大的项目上遇到的问题。所以,在你的实际程序中,你真的需要每10毫秒更新一次标签吗?如果你把它改成30呢?100? 500? 在没有峰值的情况下,您仍然可以获得良好的应用程序性能吗?是的,10是理想的。这对我来说很奇怪,因为当它单独运行时,我可以将CPU使用率保持在1%以下……考虑到你每秒调用函数100次,10%的CPU使用率似乎并不特别不寻常。您让底层库认为需要以100fps的速度重新绘制屏幕。