从Python更改光标类型

发布于 2025-02-07 08:13:18 字数 692 浏览 1 评论 0原文

我正在与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

镜花水月 2025-02-14 08:13:18

我不确定在Windows终端上放置依赖性是一个好主意,但是如果您走那条路,正确的方法是通过 json片段扩展功能。

不要冒险通过Python直接修改用户的Windows终端设置文件。如果您出现问题,用户将很不高兴,如果您的设置不佳。

JSON片段扩展使您能够创建一个单独的设置片段,该片段仅适用于您的应用程序/配置文件。

例如,创建一个片段:

{
  "profiles": [
    {
      "name": "My Game",
      "commandline": "python.exe /path/to/game.py",
      "cursorShape": "vintage",
      "font": {"face": "Consolas"}
    }
  ]
}

将此文件放入以下任意:

  • 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:

{
  "profiles": [
    {
      "name": "My Game",
      "commandline": "python.exe /path/to/game.py",
      "cursorShape": "vintage",
      "font": {"face": "Consolas"}
    }
  ]
}

Place this file in either:

  • C:\ProgramData\Microsoft\Windows Terminal\Fragments\{app-name}\{file-name}.json: For all users on the system
  • C:\Users\<user>\AppData\Local\Microsoft\Windows Terminal\Fragments\{app-name}\{file-name}.json: For only the current user
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文