pycharm 图像在Tkinter输出中不可见

cl25kdpy  于 2023-10-20  发布在  PyCharm
关注(0)|答案(2)|浏览(130)

按照下面给出的代码,我想知道它有什么问题,所以我没有得到想要的输出

from tkinter import *

# Label = an area widget that holds text and/or an image within a window
# ⬆ - up arrow

window = Tk()

photo = PhotoImage(file='cap.png')  # creating a usable photo for python as directed in gui 1

label1 = Label(window,
               text="Hello world",
               font=('Arial', 40, 'bold'),
               fg='#4e615e',
               bg='#f4f5e9',
               relief=RAISED,
               bd=10,
               padx=20,
               pady=20,
               image=photo,
               compound='bottom')
# ⬆ label1 is a unique name for our new label and Label() is a function and in the parentheses window is the location of the label and text= is a keyword argument value in the label
# ⬆ the values in red are keyword arguments

# label1.place(x=100, y=100)
# ⬆ This will still pack your label but will give you the power to place it on your wished side

label1.pack()
# ⬆ this will pack up your label and present it in the window, without .pack your label wont be visible

window.mainloop()

输出

正如你可以在上面看到的那样,我想要的输出是我的图像在底部复合,显示文本在它的顶部,但我唯一看到的是边框和背景颜色。
如果我删除图像一切原来是罚款没有它,文本是可见的,它的适当位置..
图像大小为100 x 100 Software - PyCharm MacOS - Monterey

v1l68za4

v1l68za41#

你得到这个的原因是因为图像基本上是标签的大小.当你删除图像时,标签文本会明显显示。你得在标签上填上图片的位置。

ruoxqz4g

ruoxqz4g2#

我删除了:relief=RAISED,bd=10,它显示了文本和图像

相关问题