小编 ki*_*eks的帖子

Python tkinter 性能问题

我想创建一个基于块物理的游戏,但是 fps 下降得非常快。我尝试尽可能地优化它,但它的 fps 仍然相当低(200 块给我大约 20 fps)。有谁知道如何优化我的块游戏?我本来打算添加更多内容,但看到这个问题我可能会放弃。

这是我的代码:

from tkinter import *
import math
import random
import time


master = Tk()

w = Canvas(master,width=600,height=600)
w.pack()

tileSize = 20

def randomColor():
    r = math.floor(random.random() * 255)
    g = math.floor(random.random() * 255)
    b = math.floor(random.random() * 255)
    return '#%02x%02x%02x' % (r, g, b)

class newElement:
    def __init__(self,x,y):
        x = math.floor(x/tileSize) * tileSize
        y = math.floor(y/tileSize) * tileSize
        self.x = x
        self.y = y
        self.vx = 0
        self.vy = 0
        self.width = …
Run Code Online (Sandbox Code Playgroud)

python tkinter

2
推荐指数
1
解决办法
2598
查看次数

标签 统计

python ×1

tkinter ×1