I have a Tkinter application, and I want the Label to completely take up the empty space (because I have set the Label as a background picture for my App). But when I don't specify the height and the width of the Label, it also eats up the Frame as in the code below. How to make it so that its below the Frame, but takes up the empty space???
Code -->
#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()
You can use place()
instead of pack()
on the label to fill the available space:
# As the height of the title bar is 4
# so the label height should be <window height> - 4: relheight=1, height=-4
window.place(x=0, y=4, relwidth=1, relheight=1, height=-4)