【问题标题】:Tkinter - uneven frames overlappingTkinter - 不均匀的帧重叠
【发布时间】:2021-07-23 17:57:02
【问题描述】:

有人可以确认是否有可能创建尺寸不均匀重叠的 Tkinter 框架,然后通过使用 Tkinter raise 功能,我想显示我需要的任何框架,但由于某种原因,我不能找到执行此操作的选项,非常感谢任何建议/建议。

如下图所示,黄色、绿色和红色就像是 3 个不同的帧

提前谢谢你..!!

【问题讨论】:

  • 为什么要这样重叠帧?我想不出任何有用的情况。你也看过.place几何管理器吗?
  • 您不能像这样使用透明的Frames,但您应该可以根据需要使用lift()lower 以获得效果。 Frames 必须都是兄弟姐妹。
  • @TheLizzard:我见过像这样有浮动“调色板”的 UI;通常显示信息或包含工具或选项列表 - 所以它在某些情况下绝对有用。还有一个叫MDI (Multiple-document interface)
  • @martineau 在这种情况下,我很可能会使用另一个窗口(@98​​7654329@)。我不会在主窗口中使用浮动框架。
  • 您希望所有这些框架都存在于一个窗口中,还是希望每个框架都是一个浮动窗口?

标签: python tkinter overlap frames


【解决方案1】:

是的,这是可能的,尽管框架中没有透明度。如果您真的不需要框架而只需要矩形,this answer 将展示如何使用画布上的图像获得透明度。

您的帖子不清楚您的期望,但这里有一个示例,它使用place 来排列图片中的框架。如果你运行代码,你可以点击一个框架将它提升到顶部。

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()

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-04
相关资源
最近更新 更多