Home > Software engineering >  How to make a floating Frame in tkinter
How to make a floating Frame in tkinter

Time:09-22

For my tkinter app I want to make a frame that would on top of other widgets, not taking any space (like html position fixed).

The Frame will have to contain widgets, if Frame is not possible labels or buttons will do.

I have no idea how to do it so haven't tried anything yet. Please help!

CodePudding user response:

Here is a demonstration of place manager.

Remarks in the code explain behaviour.

import tkinter as tk

root = tk.Tk()
root.geometry("868x131")
button = tk.Button(root, text = "A Button")
button.place(x = 2, y = 2)

Frame = tk.LabelFrame(root, text = "A LabelFrame using place", bg="cyan")
# Frame using place with x, y, width, height in absolute coordinates
Frame.place(x = 250, y = 20, width = 600, height = 70)

ButtonInFrame = tk.Button(Frame, text = "A Button IN LabelFrame", bg="white")
# Note: place x,y is referenced to the container (Frame)
# Note: place uses just x,y and allows Button to determine width and height
ButtonInFrame.place(x = 2, y = 2)

Label = tk.Label(root, text = "A Label on LabelFrame\nWith multiple lines\nOf Text.", bg="light green")
# Label sits on top of buttonFrame and Frame
# Note place uses just x,y and allows Label to determine width and height
Label.place(x = 330, y = 60)

root.mainloop()
  • Related