【问题标题】:Why does my personnalized frame doesn't stay when I add a smaller widget为什么我添加一个小部件时我的个性化框架没有留下来
【发布时间】:2016-08-02 09:11:54
【问题描述】:

考虑 tkinter 在 python 3.5 中使用 Tk 8.6。

注意:在以下代码中,s 指的是 ttk.Style 的一个实例。

我有一个我制作的风格的框架。它工作正常。我将它的大小设置为 562x750,因为它是图像大小。它没有错。如果需要,这是代码:

s.mainframeImage = tk.PhotoImage(file = os.path.join(IMG_DIR, "base_img", "SWTORLogo.png"))
s.element_create("mainframe.background", "image", s.mainframeImage, sticky = "nswe", height = 562, width = 750)
s.layout("mainframe.TFrame", [("Frame.border", {"sticky": "nswe", "children": [("mainframe.background",
            {"sticky": "nswe"})]})])

如果需要,这是我制作的组合框样式。我只改变了背景(Combobox.field)。

s.topComboboxImage = tk.PhotoImage(file = os.path.join(IMG_DIR, "base_img", "combobox_top.png"))
s.element_create("topCombobox.field", "image", s.topComboboxImage, sticky = "nswe", height = 65, width = 750)
s.layout("topCombobox.TCombobox", [("topCombobox.field", {"children": [("Combobox.downarrow",
            {"side": "right", "sticky": "ns"}), ("Combobox.padding", {"children": [("Combobox.textarea",
            {"sticky": "nswe"})], "expand": "1", "sticky": "nswe"})], "sticky": "nswe"})])

所以...假设上面的代码是实例化的.. 让它们出现在窗口中应该没有问题。只要我不使用框架作为组合框的父级,一切都会出现。 当我这样做时,问题就开始了。 这是我使用的代码:

myApp = tk.Tk()
getStyle(myApp)
myApp.me = ttk.Frame(myApp, style = "mainframe.TFrame", height = 562, width = 750)
myApp.me.grid(sticky = "nswe")
myApp.me.me2 = ttk.Combobox(myApp.me, style = "topCombobox.TCombobox")
myApp.me.me2.grid(column = 1, row = 1)

getStyle(myApp) 是我用来命令创建主题的函数。

所以问题是:为什么当我将框架作为父级提供给组合框时框架会消失?组合框应该更小。

【问题讨论】:

  • 经过一些工作...任何小部件都会将Frame 隐藏在后面。我怎样才能让它不会发生?

标签: tkinter python-3.5 ttk


【解决方案1】:

到处寻找之后.. 似乎 Tk 无法阻止小部件隐藏它们背后的东西。好吧,除非你使用Canvas

【讨论】:

    猜你喜欢
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    相关资源
    最近更新 更多