Python 如何让Tkinter在mac OS上看起来好看或自然?
我使用Tkinter、python 3.7.4和Mac OS Mojave 10.14.6开发了一个简单的应用程序。 我在Ubuntu18.04和最新的Windows10上执行了相同的代码,应用程序看起来是本地的。然而,当我在Macbook上运行它时,它看起来不像其他MacGUI应用程序那样是本地的 例如,请看此屏幕截图: 注意小部件上的灰色背景 以下是此操作的代码:Python 如何让Tkinter在mac OS上看起来好看或自然?,python,macos,tkinter,Python,Macos,Tkinter,我使用Tkinter、python 3.7.4和Mac OS Mojave 10.14.6开发了一个简单的应用程序。 我在Ubuntu18.04和最新的Windows10上执行了相同的代码,应用程序看起来是本地的。然而,当我在Macbook上运行它时,它看起来不像其他MacGUI应用程序那样是本地的 例如,请看此屏幕截图: 注意小部件上的灰色背景 以下是此操作的代码: import datetime import gettext import sys import time import os
import datetime
import gettext
import sys
import time
import os
import tkinter
import tkinter.ttk as ttk
from tkinter.filedialog import askopenfilename
from tkinter import *
from tkinter import filedialog
# All translations provided for illustrative purposes only.
# english
_ = lambda s: s
class MainFrame(ttk.Frame):
"Main area of user interface content."
def __init__(self, parent):
ttk.Frame.__init__(self, parent)
self.parent = parent
paddings = {'padx': 6, 'pady': 6}
self.download_location = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
ttk.Label(parent, text="Youtube Url").pack(side='top', anchor='w', **paddings)
self.entry = ttk.Entry(parent, )
self.entry.pack(side='top', fill='x', **paddings)
# todo delete this line
self.entry.insert(0, 'https://www.youtube.com/watch?v=nXait2wHOQc')
self.button = ttk.Button(parent, text="Download", command=self.do_download)
self.button.pack(side='top', **paddings, anchor='w')
# style = ttk.Style()
# style.configure('TButton', foreground="red")
# self.button.config(style='Alarm.TButton')
self.location_button = ttk.Button(parent, text="Location", command=self.browse_button)
self.location_button.pack(side='top', **paddings, anchor='w')
self.statusStringVar = StringVar()
self.statusStringVar.set('status here')
self.status = ttk.Label(parent, textvariable=self.statusStringVar, text='status', )
self.status.pack(side='top', anchor='w', fill='x', **paddings)
self.locStringVar = StringVar()
self.locStringVar.set(f"Location: {self.download_location}")
self.locationLabel = ttk.Label(parent, textvariable=self.locStringVar, )
self.locationLabel.pack(side='top', anchor='w', fill='x', **paddings)
self.mp3_check_value = StringVar()
self.mp3_checkbox = ttk.Checkbutton(parent, text='Convert to MP3')
self.mp3_checkbox.config(variable=self.mp3_check_value, onvalue='yes', offvalue='no')
self.mp3_check_value.set('yes')
self.mp3_checkbox.pack(side='top', anchor='w', **paddings)
self.progressIntVar = IntVar()
self.progressIntVar.set(0)
self.mpb = ttk.Progressbar(parent, orient="horizontal", length=200, mode="determinate")
self.mpb['variable'] = self.progressIntVar
self.mpb.pack(side='top', anchor='w', fill='x', **paddings)
self.mpb["maximum"] = 100
# self.mpb["value"] = 0
def do_download(self):
pass
def progress_hook(self, d):
pass
def browse_button(self):
filename = filedialog.askdirectory()
print(filename)
self.download_location = filename
self.locStringVar.set(f"Location: {self.download_location}")
class Application(tkinter.Tk):
"Create top-level Tkinter widget containing all other widgets."
def __init__(self):
tkinter.Tk.__init__(self)
self.wm_title('Tkinter YDL')
self.wm_geometry('640x480')
self.mainframe = MainFrame(self)
self.mainframe.pack(side='right', fill='y')
if __name__ == '__main__':
APPLICATION_GUI = Application()
APPLICATION_GUI.mainloop()
我是不是遗漏了什么?请提供帮助。
ttk
小部件是“主题化”的,因此您可以通过创建自定义主题使它们在MacOS上看起来更为原生。这里有一点关于它们的内容(有些过时,但仍然适用)。但这些小部件不是都是本地的吗?也许我只需要将框架的背景更改为macs颜色。@osama7901:如果您找到了解决方案,请将其作为您自己问题的答案发布在这里,这是允许的,供其他人使用。