如何在 Tkinter 中将图像插入矩形

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

我不知道如何将图像插入矩形。我正在使用 TKinter。 我有一个长矩形,我想将图像插入到左角,但是如何插入?

from tkinter import *
from tkinter import ttk
root = Tk()

#root.attributes("-fullscreen", True)
root.wm_attributes("-alpha", 1)
root.geometry("300x2000")
root.resizable(width=False, height=False)


head = Canvas(bg="orange", width=1000, height=1000)
head.pack(anchor=NW, expand=1)
im = PhotoImage(file="top.png", width=100, height=100)
label = ttk.Label( image=im, anchor= NW)
head.create_image(1,1 , anchor=NW, image=im)


root.mainloop()

图片被裁剪了

python tkinter
1个回答
0
投票

我有一个长矩形,我想在左侧插入图像 角落,但是怎么办?

问题可以解决。

更改索引值:

im = PhotoImage(file="top.png", width=100, height=100)

将值设置为 400 和 1000:

im = PhotoImage(file="p2.png", width=400, height=1000)

截图:

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