Ttkbootstrap 仪表小部件文档示例不起作用

问题描述 投票:0回答:2

我尝试了 ttkbootstrap 的仪表小部件的示例,但它似乎不起作用。我复制并粘贴了确切的代码,并收到此错误“AttributeError:模块“PIL.Image”没有属性“CUBIC”。您是指:“BICUBIC”吗?'

这是代码

import ttkbootstrap as ttk
from ttkbootstrap.constants import *

app = ttk.Window()

meter = ttk.Meter(
    metersize=180,
    padding=5,
    amountused=25,
    metertype="semi",
    subtext="miles per hour",
    interactive=True,
)
meter.pack()

# update the amount used directly
meter.configure(amountused = 50)

# update the amount used with another widget
entry = ttk.Entry(textvariable=meter.amountusedvar)
entry.pack(fill=X)

# increment the amount by 10 steps
meter.step(10)

# decrement the amount by 15 steps
meter.step(-15)

# update the subtext
meter.configure(subtext="loading...")

app.mainloop()
`

Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\ttkbootstrap\gui-intro\meter\main.py", line 6, in <module>
    meter = ttk.Meter(
            ^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\ttkbootstrap\venv\Lib\site-packages\ttkbootstrap\widgets.py", line 718, in __init__
    self._setup_widget()
  File "C:\Users\User\PycharmProjects\ttkbootstrap\venv\Lib\site-packages\ttkbootstrap\widgets.py", line 759, in _setup_widget
    self._draw_meter()
  File "C:\Users\User\PycharmProjects\ttkbootstrap\venv\Lib\site-packages\ttkbootstrap\widgets.py", line 856, in _draw_meter
    img.resize((self._metersize, self._metersize), Image.CUBIC)
                                                   ^^^^^^^^^^^
AttributeError: module 'PIL.Image' has no attribute 'CUBIC'. Did you mean: 'BICUBIC'?

Process finished with exit code 1
tkinter pycharm ttkwidgets ttkbootstrap
2个回答
1
投票

由于属性

Image.CUBIC
已弃用(由
Image.BICUBIC
取代)并在
Pillow
v10.0.0 中删除。安装旧版本 (v9.5.0) 的
Pillow
模块或在导入
ttkbootstrap
模块之前显式创建属性:

from PIL import Image
Image.CUBIC = Image.BICUBIC
import ttkbootstrap as ttk
...

0
投票

从 PIL 导入图像 图像.CUBIC = 图像.BICUBIC

它正在工作! 谢谢

© www.soinside.com 2019 - 2024. All rights reserved.