特金特笔记本.tab:文本(标题)显示不正确

2024-09-30 02:15:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个自己的框架,为此我想在苹果电脑上使用tkinter制作一个GUI。在

在Mac OS X上,notebook.tabstext(标题)似乎没有正确显示,如下所示:

enter image description here

如您所见,text不是水平居中的,而是稍微移到顶部。在

我的代码如下:

#!/usr/bin/env python3
# coding: utf-8

import tkinter as tk
from tkinter import ttk


class SpiderGUI():
    def __init__(self, master):
        self.master = master
        self.frame = ttk.Frame(self.master, padding=(10, 10, 10, 10))
        self.frame.pack(fill="both", expand="True")

        self.paned_window = ttk.Panedwindow(self.frame, orient="horizontal")
        self.paned_window.pack(fill="both", expand="True")

        self.frame_settings = ttk.Frame(self.paned_window, width=75, height=300, relief="sunken")
        self.paned_window.add(self.frame_settings)
        self.frame_output   = ttk.Frame(self.paned_window, width=950, height=300, relief="sunken")
        self.paned_window.add(self.frame_output, weight="4")
        self.frame_logging  = ttk.Frame(self.paned_window, width=175, height=500, relief="sunken")
        self.paned_window.add(self.frame_logging)


        self.console_notebook = ttk.Notebook(self.frame_output)
        self.console_notebook.pack()

        self.frame_tab_console = ttk.Frame(self.console_notebook)
        self.console_notebook.add(self.frame_tab_console, text="Console", padding=(10))

        self.frame_tab_database = ttk.Frame(self.console_notebook)
        self.console_notebook.add(self.frame_tab_database, text="MongoDB")

def main():
    root = tk.Tk()
    app = SpiderGUI(root)
    # root.geometry(newGeometry="1200x800+100+100")
    root.title('name')
    root.resizable(width=True, height=False)
    # root.maxsize(width=1280, height=1024)
    # root.minsize(width=640, height=480)

    root.mainloop()


if __name__ == '__main__':
    main()

Tags: textselfmasteraddrootwindowwidthframe
2条回答

最好将mrushabh回答的修复应用于OSX,如下所示:

root = tk.Tk()

# a fix for running on OSX - to center the title text vertically
if root.tk.call('tk', 'windowingsystem') == 'aqua':  # only for OSX
    s = ttk.Style()
    # Note: the name is specially for the text in the widgets
    s.configure('TNotebook.Tab', padding=(12, 8, 12, 0))

如果有人还需要解决这个问题。这很老套,但很管用:

s = ttk.Style()
s.configure('TNotebook.Tab', padding=(20, 8, 20, 0))

相关问题 更多 >

    热门问题