是否可以在Tkinter中放置图像而不使用标签或画布

2024-06-02 12:01:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将图像并排放置,但标签重叠,标签突出

from tkinter import *
root = Tk()
root.geometry("1000x700")
root.resizable(0, 0)
##############################################
TFi = PhotoImage(file="images/Topframe.png")
TF = Label(root, image=TFi)
TF.place(x=-3, y=-3)
BFi = PhotoImage(file="images/Botframe.png")
BF = Label(root, image=BFi)
BF.place(x=-3, y=650)
LF1i = PhotoImage(file="images/LeftFrame1.png")
LF1 = Label(root, image=LF1i)
LF1.place(x=-3, y=50)
##############################################
root.mainloop()

Tags: imagepngtfplaceroot标签labelfile
1条回答
网友
1楼 · 发布于 2024-06-02 12:01:52

Is it possible to place an image in Tkinter without a Label or canvas

最常见的标签选择是画布或标签。您还可以在按钮上放置图像,并将其嵌入文本小部件中

创建相邻标签的最佳选择是使用packgrid^{<如果您创建单个水平或垂直分组,cd1>}是好的,但是如果您同时创建小部件的行和列,grid则更好

您可以使用place,但这需要您计算每个图像的位置,并且通常会导致用户界面对屏幕分辨率的变化不是很有弹性。它有时也会导致您不得不对每个小部件进行更改,即使您只想稍微调整布局

我对它们重叠的原因的猜测是,您不知道默认情况下,您给出的坐标place指定了图像的中心,而不是左上角。您可以使用anchor选项指定图像的哪个部分位于给定的坐标处

the label sticks out.

我不太清楚你的意思,但如果你是说它有3D外观,你可以通过给它一个borderwidth的零和/或一个relief"flat"来控制它

相关问题 更多 >