0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

スクショに説明をつけるためだけの簡易メモ帳をPython+WebViewで作った

Posted at

image.png

↑こういう「何もしない」エディタ作った。

完成ソース

fukidasih.py
import webview

HTML = """
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
    html, body {
      height: 100%;
      margin: 0;
      padding: 0;
      width: 100%;
      overflow: hidden;
    }
    textarea {
      width: 100vw;
      height: 100vh;
      box-sizing: border-box;
      font-size: 3em;
      border: 5px solid red;
      border-radius: 2px;
      resize: none;
      outline: none;
      margin: 0;
      padding: 5px;
    }
  </style>
</head>
<body>
  <textarea autofocus></textarea>
  <script>
    const textarea = document.querySelector('textarea');
    let fontSize = 3;
    window.addEventListener('keydown', function(event) {
      if (event.ctrlKey) {
        if (event.key === '+' || event.key === '=') {
          fontSize += 0.1;
          textarea.style.fontSize = fontSize + 'em';
          event.preventDefault();
        } else if (event.key === '-') {
          fontSize = Math.max(0.5, fontSize - 0.1);
          textarea.style.fontSize = fontSize + 'em';
          event.preventDefault();
        }
      }
    });
  </script>
</body>
</html>
"""

if __name__ == '__main__':
    webview.create_window(
        "",
        html=HTML,
        width=600,
        height=200,
        resizable=True  # デフォルトでTrueですが明示しています
    )
    webview.start()

動作を確認したはWindows11のみです。

作った背景

  • スクショに吹き出しをつけるだけの仕事が多すぎる
  • GoogleSlideに貼り付けて吹き出しをつけるんだけど、結局またそれもスクショにしてSlackとかに送ることになる。そしてGoogleSlideは自動的にファイルができちゃうのが邪魔
  • メモ帳はメニューバーが邪魔
  • windowsのpython+Webviewが一番シンプルなGUIなのではないかと思って試してみたかった

本当はやりたかったけどやってないこと

  • タイトルバーも消したかったけど、タイトルバーも消すと移動も終了もできなくなって不便だった
  • 半透明にしたかったけど、透明にするとエディタにフォーカスがいかなかった
  • Electronはタイトルバー消したり半透明にしたりできるけど、そこまでの大げさなものは要らない

満足したところ

  • Windows+Pythonでフレームワークに頼らずペラ1のGUIアプリが作れた
  • これといったデザインオプションなどないが、ソースを直接いじればいいのであとはお前ら好きなようにいじれと言える
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?