【发布时间】:2018-06-04 09:22:20
【问题描述】:
我正在尝试在 Macos (Python 2.7) 上的 Tkinter 中创建一个 GUI 应用程序。我按照教程创建了大纲,但选项卡按钮中的文本是顶部对齐的,即使没有指定该方向的任何内容。我怎样才能让它居中without using a custom theme?
#!/usr/bin/python
from Tkinter import *
import ttk
main = Tk()
main.title('Mie Solver')
main.geometry("640x320")
rows = 20
columns=2
main.rowconfigure(rows, weight=1)
main.columnconfigure(columns, weight=1)
nb = ttk.Notebook(main)
nb.grid(row=1, column=0, columnspan=20, rowspan=20, sticky='NESW')
nb.enable_traversal()
model_tab = ttk.Frame(nb)
nb.add(model_tab, text='Model')
solver_tab = ttk.Frame(nb)
nb.add(solver_tab, text='Solver')
cs_tab = ttk.Frame(nb)
nb.add(cs_tab, text='Cross Section')
results_tab = ttk.Frame(nb)
nb.add(results_tab, text='Results')
# Model Tab:
ttk.Label(model_tab, text="Geometry").grid(row=1, column=0, sticky=W)
Radiobutton(model_tab, text="Solid Sphere").grid(row=2, column=0, sticky=W)
ttk.Radiobutton(model_tab, text="Core-Shell").grid(row=3, column=0, sticky=W)
ttk.Radiobutton(model_tab, text="Cylinder").grid(row=4, column=0, sticky=W)
ttk.Separator(model_tab, orient=HORIZONTAL).grid(row=5, column=0, sticky=EW)
main.attributes("-topmost", True)
main.mainloop()
【问题讨论】:
-
你为什么反对自定义主题?
-
@BryanOakley 因为如果可能的话,我希望界面在不同平台上看起来是原生的。据我了解,如果我做一个自定义样式,外观基本上是固定的,对吧?
-
您可以先命名您所在的操作系统,然后根据需要应用客户样式。我相信您可以使用
import os然后print(os.name)来检查您使用的操作系统。将此与您需要具有服装风格的操作系统名称列表结合起来,您应该能够解决这个问题。您也可以使用平台库中的platform.system()。