我有一个 Tkinter 应用程序,我希望标签完全占据空白空间(因为我已将标签设置为我的应用程序的背景图片)。但是当我没有指定标签的高度和宽度时,它也会像下面的代码一样吃掉框架。如何使其位于框架下方,但占用空白空间???
代码 -->
#importing everything
from tkinter import *
from pypresence import Presence
import time
#making the root window
root = Tk()
dimension = '800x500'
#setting the window
bg = PhotoImage(file = r'C:\Users\Hunter\Desktop\school 1\module\pbm\bg.png')
window = Label(root, bd=0, image=bg)
window.pack(fill=BOTH, expand=True, side=BOTTOM)
#overriding the default properties
root.overrideredirect(True)
root.geometry(dimension)
#the main title bar
title_bar = Frame(root, bg='#496E82', bd=0, height=4)
#pack all the widgets
title_bar.pack(fill=X, side=TOP)
#code for moving the window
def get_pos(event):
xwin = root.winfo_x()
ywin = root.winfo_y()
startx = event.x_root
starty = event.y_root
ywin = ywin - starty
xwin = xwin - startx
def move_window(event):
root.geometry(dimension + '+{0}+{1}'.format(event.x_root + xwin, event.y_root + ywin))
startx = event.x_root
starty = event.y_root
title_bar.bind('<B1-Motion>', move_window)
#binding the title bar so that it moves
title_bar.bind('<Button-1>', get_pos)
#main thing
root.mainloop()