简体   繁体   English

Tkinter - 不均匀的帧重叠

[英]Tkinter - uneven frames overlapping

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.有人可以确认是否有可能创建具有不均匀尺寸重叠的 Tkinter 框架,然后通过使用 Tkinter raise 功能,我想显示我需要的任何框架,但由于某种原因,我找不到选项为此,非常感谢任何建议/建议。

Something like the below in the image, yellow, green & red like to be 3 different frames类似于图像中的下图,黄色、绿色和红色就像是 3 个不同的框架

Thank you in advance..!!先感谢您..!!

在此处输入图片说明

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.您的帖子并不清楚您所期望的确切内容,但这里有一个示例,该示例使用place来排列图片中的框架。 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()

屏幕截图,顶部为红色

屏幕截图,顶部为绿色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM