MacOS 的 platform.system() 输出是什么?
What is platform.system() output for MacOS?
我正在制作一个 python 应用程序(希望)OS 不可知。这是在 python3.7 中编写的,GUI 是从 Tkinter8.6 构建的。我正在尝试使用 platform.system() 来确定 OS 系列。
我正在使用两个命令之一设置 tkinter 边框全屏,具体取决于 OS.The 问题是我不明白应该为 MacOS.[=14= 打印哪个平台]
我使用的代码大致如下所示:
from tkinter import *
from tkinter import ttk
import platform
root = Tk()
system = platform.system()
if system == 'Windows':
root.state('zoomed')
elif system == 'Linux' or system == 'Darwin':
root.attributes('-zoomed', True)
elif system == '':
expectation = "Expected: 'Linux' 'Windows' or 'Darwin', Received: "
raise OSError(expectation + system)
人们的例子和文档是冲突的,我没有 Mac 来测试它。
docs说:"Returns the system/OS name, e.g. 'Linux', 'Windows', or 'Java'..."
几个人的帖子不断重复:"will return darwin for MacOS"
您正在使用 platform
库 (platform.system() == 'Darwin'
)。您链接到的 post 使用 sys
库 (sys.platform == 'darwin'
)。对于您正在使用的库,字符串为 'Darwin'。我希望这有帮助。
我正在制作一个 python 应用程序(希望)OS 不可知。这是在 python3.7 中编写的,GUI 是从 Tkinter8.6 构建的。我正在尝试使用 platform.system() 来确定 OS 系列。
我正在使用两个命令之一设置 tkinter 边框全屏,具体取决于 OS.The 问题是我不明白应该为 MacOS.[=14= 打印哪个平台]
我使用的代码大致如下所示:
from tkinter import *
from tkinter import ttk
import platform
root = Tk()
system = platform.system()
if system == 'Windows':
root.state('zoomed')
elif system == 'Linux' or system == 'Darwin':
root.attributes('-zoomed', True)
elif system == '':
expectation = "Expected: 'Linux' 'Windows' or 'Darwin', Received: "
raise OSError(expectation + system)
人们的例子和文档是冲突的,我没有 Mac 来测试它。
docs说:"Returns the system/OS name, e.g. 'Linux', 'Windows', or 'Java'..."
几个人的帖子不断重复:"will return darwin for MacOS"
您正在使用 platform
库 (platform.system() == 'Darwin'
)。您链接到的 post 使用 sys
库 (sys.platform == 'darwin'
)。对于您正在使用的库,字符串为 'Darwin'。我希望这有帮助。