从Python更改光标类型
我正在与Python一起制作基于文本的视频游戏,我需要一种从内部Python更改光标类型的方法。这是我的代码:
from os import system,getenv
from json import loads,dumps
import uuid
apd = getenv("LOCALAPPDATA")
pf = loads(open(rf"{apd}\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json").read())
pf['profiles']['list'].append({"guid":str(uuid.uuid4()),'name':"Game","commandline": "C:\\Windows\\System32\\cmd.exe","cursorShape": "vintage","font": {"face": "Consolas"},})
open(rf"{apd}\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json",'w').write(dumps(pf))
system('wt -F -d {{PATH TO FILE}} -p "Game" --title Game python game.py')
I am making a text based video game with python, and I need a way to change the cursor type from inside python. Here is my code:
from os import system,getenv
from json import loads,dumps
import uuid
apd = getenv("LOCALAPPDATA")
pf = loads(open(rf"{apd}\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json").read())
pf['profiles']['list'].append({"guid":str(uuid.uuid4()),'name':"Game","commandline": "C:\\Windows\\System32\\cmd.exe","cursorShape": "vintage","font": {"face": "Consolas"},})
open(rf"{apd}\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json",'w').write(dumps(pf))
system('wt -F -d {{PATH TO FILE}} -p "Game" --title Game python game.py')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定在Windows终端上放置依赖性是一个好主意,但是如果您走那条路,正确的方法是通过 json片段扩展功能。
不要冒险通过Python直接修改用户的Windows终端设置文件。如果您出现问题,用户将很不高兴,如果您的设置不佳。
JSON片段扩展使您能够创建一个单独的设置片段,该片段仅适用于您的应用程序/配置文件。
例如,创建一个片段:
将此文件放入以下任意:
c:\ programData \ Microsoft \ Windows terminal \ fragments \ {app-name} \ {file-name} .json .json
:for on所有用户上的所有用户系统c:\ user \< user> \ appdata \ local \ Microsoft \ Microsoft \ Windows \ Windows terminal \ fragments \ {app-name} \ {file-name} .json .json
:仅适用于当前用户I'm not sure it's a great idea to place a dependency on Windows Terminal, but if you do go that route, the right way to do this is via the JSON fragment extension feature.
Don't risk modifying the user's Windows Terminal settings file directly via Python. Users will be quite (rightly) upset if you muck up their settings if something goes wrong.
JSON fragment extensions give you the ability to create a separate settings fragment that only applies to your application/profile.
For example, create a fragment:
Place this file in either:
C:\ProgramData\Microsoft\Windows Terminal\Fragments\{app-name}\{file-name}.json
: For all users on the systemC:\Users\<user>\AppData\Local\Microsoft\Windows Terminal\Fragments\{app-name}\{file-name}.json
: For only the current user