我正在Python3 / Tkinter中维护一个应用程序,并添加了我的第一个用户在MacOS上打开的问题。这是Windows上1080p的主屏幕(Linux显示类似结果):
在2560 x 1600的MacOS上,UI中的所有内容均按2x大小近似缩放:
原始代码是这样的:
self.window = Tk.Tk()
self.window.resizable(False,False)
if platform.system() == 'Windows' :
self.window.iconbitmap('bestarcade.ico')
self.window.title(title)
我尝试执行解决方案:
self.scriptDir = scriptDir
self.window = Tk.Tk()
self.window.geometry("930x950")
self.window.resizable(False,False)
更糟糕的是,MacOS中的应用程序窗口被缩短了一点
我尝试缩放:
self.scriptDir = scriptDir
self.window = Tk.Tk()
self.window.tk.call('tk','scaling',0.5)
self.window.resizable(False,False)
而且它与标准解决方案没有任何改变,好像没有考虑在内
现在,从我阅读的内容来看,这似乎是MacOS上的Tkinter错误,而我发现的唯一解决方案要求为每种字体和UI组件或类似内容硬设置尺寸
Is there anything more simple I could try ?
So the solution, as @Bryan Oakley proposed, is juste to change the size of the default fonts on Mac OS. Now I wanted something user friendly, as I noticed the result on my macbook was also different from the one given by the user.
I chose to use a Scale Tkinter component to allow the user to change the size of the font himself :
EDIT : kept for the sake of the solution, but actually the Scale widget doesn't seem to be compatible with all MacOS version either, as it doesn't appear at all on some of them.
First initialization of the GUI :
class GUI():
MACOS_DEFAULT_FONT_SIZE = 7
DEFAULT_FONT_SIZE = 9
def __init__(self,scriptDir,logger,title) :
self.scriptDir = scriptDir
self.window = Tk.Tk()
self.window.resizable(False,False)
self.startFontSize = self.DEFAULT_FONT_SIZE
if platform.system() == 'Windows' :
self.window.iconbitmap('bestarcade.ico')
elif platform.system() == 'Darwin' :
# Handle tkinter font size bug on MacOS
self.startFontSize = self.MACOS_DEFAULT_FONT_SIZE
self.setFontSize(self.startFontSize)
self.window.title(title)
self.logger = logger
def draw(self) :
self.root = Tk.Frame(self.window,padx=10,pady=5)
self.root.grid(column=0,row=0)
self.drawSliderFrame()
self.drawMainframe()
self.window.mainloop()
Then in the same class, creation of the scale component and its event handler (also used during initialization of the GUI) :
def setFontSize(self, value) :
default_font = Font.nametofont("TkDefaultFont")
default_font.configure(size=value)
text_font = Font.nametofont("TkTextFont")
text_font.configure(size=value)
fixed_font = Font.nametofont("TkFixedFont")
fixed_font.configure(size=value)
def drawSliderFrame(self) :
self.sliderFrame = Tk.Frame(self.root,padx=10,pady=0)
self.sliderFrame.grid(column=0,row=0,sticky="EW",pady=0)
self.sliderFrame.grid_columnconfigure(0, weight=1)
self.slider = Tk.Scale(self.sliderFrame, from_=4, to=12, orient=Tk.HORIZONTAL, showvalue=0, command=self.setFontSize)
wckToolTips.register(self.slider, 'Window Size') #TODO internationalization
self.slider.grid(column=0,row=0,sticky="W",pady=0)
self.slider.set(self.startFontSize)
尽管它不能解决围绕分辨率和屏幕尺寸的所有问题,但似乎似乎还行得通,尽管与自动完成操作相比,可能不得不将窗口的尺寸减小一些一点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句