python - 更改窗口大小时如何更快地加载背景图像?
问题描述
import tkinter as tk
from tkinter import ttk
from PIL import ImageTk, Image
class Application(tk.Frame):
'''Application root window'''
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.parent = parent
self.pack(expand=1)
root.title("Library")
root.minsize(width=400, height=400)
root.geometry("600x600")
self.image=Image.open('lib4.jpg')
self.img_copy = self.image.copy()
self.background_image = ImageTk.PhotoImage(self.image)
self.background = tk.Label(self, image=self.background_image)
self.background.pack(fill=tk.BOTH, expand=tk.YES)
self.background.bind('<Configure>', self._resize_image)
def _resize_image(self, event):
new_width = event.width
new_height = event.height
self.image = self.img_copy.resize((new_width, new_height))
self.background_image = ImageTk.PhotoImage(self.image)
self.background.configure(image=self.background_image)
if __name__ == "__main__":
root = tk.Tk()
app = Application(parent=root)
app.mainloop()
我正在尝试根据窗口大小调整背景图像的大小,但是当我更改窗口大小时,它会逐渐调整。我怎样才能使它快速?提前致谢。
解决方案
推荐阅读
- android - Android - fitSystemWindows 不能与 ViewPager.setAdapter 一起使用
- java - 按降序对 Firebase 数据进行排序
- sql - SQL 中的数据转换:根据列中的值从数据集中删除帐户信息
- svelte - 如何在 Sapper.js 项目上动态更改 og 元标记
- c++ - C ++如何在堆栈中存储唯一指针,并允许对象将指针从堆栈中取出(并获得所有权)
- java - c#解压错误存档条目是使用不支持的压缩方法压缩的
- c# - Unity2D 世界生成错误
- rust - 调用 Rust 结构函数后“借用移动值”
- html - 将边框底部添加到 Bootstrap 导航栏链接
- reactjs - 如何集成两个创建反应应用程序项目或其构建?