gpt4 book ai didi

python kwargs 表达式评估

转载 作者:太空宇宙 更新时间:2023-11-03 15:13:41 24 4
gpt4 key购买 nike

关于将复杂表达式作为关键字参数传递,有什么我应该知道的吗?我遇到的例子是在 tkinter 中:

image = gui.utils.get_image(self.get_icon('pause'), dimensions=(50, 50))
button = ttk.Label(self.mainframe, image=image)
button.place(x=0, y=-10, relwidth=1, relheight=1)

有效,但以下无效:

button = ttk.Label(self.mainframe, image=gui.utils.get_image(self.get_icon('pause'), dimensions=(50, 50)))
button.place(x=0, y=-10, relwidth=1, relheight=1)

有什么区别? gui.utils.get_image(self.get_icon('pause'), dimensions=(50, 50)) 应该在我将它传递给构造函数时进行评估。这是 python 中的错误(我在 2.7 上),还是 tkinter 的错误?如果有帮助,我将在子线程中运行此代码,但我不会引用此线程外的任何对象。

编辑:

“作品”是指将所需图像附加到标签的背景。在第二个示例中,标签以正确的大小和位置显示,但背景为空白。

最佳答案

您需要保留对图像的引用。 Otherwise, as Fredrik Lundh explains ,

Tkinter tells Tk to release the image. But since the image is in use by a widget, Tk doesn’t destroy it. Not completely. It just blanks the image, making it completely transparent…

关于python kwargs 表达式评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23479202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com