为何无法同时修改屏幕尺寸与颜色?Python os.system调用问题
解决方法
你当前的代码中,连续两次给cmd变量赋值,第二次的mode 200,30会完全覆盖第一次的color 1F,所以os.system(cmd)只会执行最后一次赋值的命令。以下是两种可行的解决方式:
- 方案一:分开执行每个命令
直接对两个命令分别调用os.system,确保每个命令都被执行:
import os # Set the output screen size and color os.system('color 1F') os.system('mode 200,30')
- 方案二:用命令连接符合并成一条命令
在Windows CMD中,使用&可以将多个命令按顺序串联执行,这样只需一次os.system调用:
import os # Set the output screen size and color cmd = 'color 1F & mode 200,30' os.system(cmd)
内容的提问来源于stack exchange,提问作者user19568486
相关产品推荐
相关产品推荐

