Skip to content

[Tkinter] [MacOS] [Python 3.10]: Setting value of ttk.Progressbar once will permanently increase CPU usage of application #93037

@fladd

Description

@fladd

Bug report

Setting the value of a ttk.Progressbar once, will permanently increase CPU usage. The increase in CPU usage scales with the amount of widgets in the applications (yes, the other widgets seemingly unrelated to the Progressbar). In a more complex GUI, CPU usage can increase significantly (to over 90% on my system, with the fans being quite busy).

The problem can be demonstrated with the following simple test script:

import random
import tkinter as tk
import tkinter.ttk as ttk

class App(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.grid()
        self.bar = ttk.Progressbar(self, orient="horizontal",
                                   mode='determinate', length=500, maximum=100,
                                   value=0)
        self.bar.grid(row=0, column=0)
        self.label = ttk.Label(
            self,
            text="Pressing button ONCE will permanently increase CPU usage!")
        self.label.grid(row=1, column=0)
        self.button = ttk.Button(self, text="Change Progressbar",
                                 command=self.rand_pos)
        self.button.grid(row=2, column=0)

    def rand_pos(self):
        pos = random.randint(0,100)
        self.bar["value"] = pos


if __name__ == "__main__":
    root = tk.Tk()
    root.title("Tkinter Bug")
    app = App(root)
    app.mainloop()

Comparing samples of the Python process before and several minutes after setting a Progressbar value (with no other interaction with the GUI), seems to indicate that Tk enters a state in which it tries to constantly update all widgets in the GUI.

NOTE: This problem does not occur with Python 3.9.5 on the same machine!

Your environment

MacBook Pro (Retina, 15-inch, Late 2013)
2 GHz Quad-Core Intel Core i7
8 GB 1600 MHz DDR3
Intel Iris Pro 1536 MB

  • CPython versions tested on: Python 3.10.4 (official installer from python.org)
  • Operating system and architecture: macOS Catalina 10.15.7 (19H15) x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions