我正在尝试创建自己的框架,为此,我想在Apple计算机上使用tkinter制作GUI.
似乎Notebook.tabs的文本(标题)未在Mac OS X上正确显示,如下所示:
如您所见,文本不是水平居中,而是略微移到顶部.
我的代码如下:
#!/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()
解决方法:
如果还有其他人需要解决方案.这很骇人,但有效:
s = ttk.Style()
s.configure('TNotebook.Tab', padding=(20, 8, 20, 0))