简体   繁体   English

tkinter笔记本python选项卡标题重叠

[英]tkinter notebook python tab titles overlapping

Quick question all, 快速提问

My (very simple) tkinter GUI program: 我的(非常简单的)tkinter GUI程序:

import tkinter as tk
from tkinter import ttk

if __name__ == "__main__":
    root = tk.Tk()
    test = ttk.Notebook(root)
    test.grid()
    tab1 = ttk.Frame(test)
    tab2 = ttk.Frame(test)
    tab3 = ttk.Frame(test)

    test.add(tab1, text="1")
    test.add(tab2, text="Tab Two")
    test.add(tab3, text="Tab Three")

    root.title("CONTROL PANEL")
    root.mainloop()

Result: 结果:

在此处输入图片说明

Why is the second tab being overlapped by the third? 为什么第二个标签页与第三个标签页重叠?

Initially, i thought it was a grid option that i had missed but i could not find the relevant option. 最初,我认为这是我错过的网格选项,但我找不到相关的选项。 Thanks guys. 多谢你们。

EDIT: This occurs when tab 1 has a short title. 编辑:当选项卡1包含简短标题时,会发生这种情况。

This seems to be an issue with the following themes: (' winnative ', 'clam', ' alt ', ' default ', 'classic', ' vista ', ' xpnative ') 这似乎与以下主题有关:(“ winnative ”,“ clam”,“ alt ”,“ default ”,“ classic”,“ vista ”,“ xpnative ”)

When either a 'clam' or 'classic' style is used, the tab titles fit. 当使用“蛤”或“经典”样式时,选项卡标题会适合。 ie

import tkinter as tk
from tkinter import ttk

if __name__ == "__main__":

    root = tk.Tk()
    test = ttk.Notebook(root)
    test.grid()
    tab1 = ttk.Frame(test)
    tab2 = ttk.Frame(test)
    tab3 = ttk.Frame(test)

    # added code to change style
    s = ttk.Style(test)
    s.theme_use('STYLE AS ABOVE')
    ############################

    test.add(tab1, text="1")
    test.add(tab2, text="Tab Two")
    test.add(tab3, text="Tab Three")

    root.title("CONTROL PANEL")
    root.mainloop()

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

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