0

Could someone please confirm if there is any possibility to create Tkinter frames with uneven dimensions overlapping, and then by using Tkinter raise function, I would like to display whichever frames is required to me, but for some reason, I couldn't find an option to do this, any suggestions/advises are much appreciated.

Something like the below in the image, yellow, green & red like to be 3 different frames

Thank you in advance..!!

enter image description here

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    Why do you want frames to overlap like that? I can't think of any cases where that would be useful. Also have you looked at the `.place` geometry manager? – TheLizzard Jul 23 '21 at 17:59
  • You can't have transparent `Frame`s like that but you should be able to `lift()` or `lower` them as needed to get the effect. The `Frame`s must all be siblings. – martineau Jul 23 '21 at 18:54
  • @TheLizzard: I've seen UI's that have floating "palettes" like this; typically showing information or containing a list of tools or options — so it definitely can be useful in some instances. There's also something called [MDI (Multiple-document interface)](https://en.wikipedia.org/wiki/Multiple-document_interface). – martineau Jul 23 '21 at 18:57
  • @martineau In that case, I am very likely to use another window (with `overrideredirect`). I wouldn't use a floating frame in the main window. – TheLizzard Jul 23 '21 at 19:02
  • @TheLizzard: That would work of course, but isn't the same thing. MDI has been around a *long* time and been used by [many applications](https://en.wikipedia.org/wiki/Multiple-document_interface#Application_examples) — so at least some folks think there are cases where it's useful. That's the point I'm making to counter yours. – martineau Jul 23 '21 at 19:11
  • 2
    do you expect all of these frames to exist in a single window, or do you want each frame to be a floating window? – Bryan Oakley Jul 23 '21 at 19:19
  • My requirement is to sit all 3 frames on a single window, I remember sometime back @Bryan Oakley mentioned it's possible in one of the old posts, my apologies if I misunderstood that. – user3101632 Jul 23 '21 at 21:14

1 Answers1

0

Yes, this is possible, though not with transparency in the frames. If you don't really need frames and just need rectangles, this answer shows how to get transparency with images on a canvas.

Your post is unclear as to exactly what you expect, but here's an example that uses place to arrange the frames like in your picture. If you run the code, you can click on a frame to raise it to the top.

import tkinter as tk

root = tk.Tk()
root.geometry("800x800")

yellow_frame = tk.Frame(root, width=800, height=300, background="yellow", bd=8, relief="solid")
green_frame = tk.Frame(root, width=800, height=300, background="green", bd=8, relief="solid")
red_frame = tk.Frame(root, width=200, height=800, background="red", bd=8, relief="solid")

yellow_frame.place(x=0, y=0, anchor="nw")
green_frame.place(x=0, y=300, anchor="nw")
red_frame.place(x=500, y=0, anchor="nw")

for frame in (yellow_frame, green_frame, red_frame):
    frame.bind("<1>", lambda event: event.widget.lift())

root.mainloop()

screenshot, red on top

screenshot, green on top

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • @user3101632: see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – Bryan Oakley Jul 27 '21 at 16:53