【发布时间】:2021-02-24 08:43:29
【问题描述】:
我正在为 Windows 制作一个 tkinter 应用程序,我想让小部件放置动态化。就像在this picture 中一样,Label(它就像一个背景图像支架)覆盖了 Y 轴,但是当我最大化窗口时,比如here,照片并没有覆盖整个 Y 轴.
如何解决这个问题,或者有没有办法在不使用root.overridedirect() 的情况下禁用窗口的最大化按钮?
这里是代码→
#importing everything
from tkinter import *
from pypresence import Presence
import time
#making the root window
root = Tk()
dimension = (
800,
500
)
#setting the window
bg = PhotoImage(file = r'C:\Users\Hunter\Desktop\school 1\module\pbm\bg.png')
background = Label(root, bd=0, image=bg)
background.place(x=0, y=0, relwidth=1, relheight=1)
root.geometry(f'{dimension[0]}x{dimension[1]}')
#main thing
root.mainloop()
【问题讨论】:
-
试试
background.pack(fill="both")而不是background.place(x=0, y=0, relwidth=1, relheight=1) -
使用
root.resizable(0, 0)禁用maximize按钮。否则,无论何时调整根窗口的大小,您都需要调整图像大小。 -
拥有动态 tkinter 应用程序的第一步是使用网格或打包方法而不是放置。
-
您可以使用
root.resizable(0, 0)禁用最大化按钮。
标签: python python-3.x user-interface tkinter tkinter-label