[Python] メモ帳っぽいもの作ってみました by yasu

View this thread on steempeak.com
· @yasu · (edited)
$20.21
[Python] メモ帳っぽいもの作ってみました
こんにちは、@yasuです。

今回はメモ帳っぽいもの作りながら学習してみたいと思います。

* 今回、テキストを保存するファイル名は固定
* テキストにスクールバーをつける
* メニューをつける

### 実行環境
* https://repl.it/ ではなく Visual Studio Codeで行います
* tkinterライブラリ使用

### コード
```
import os
from tkinter import *

root = Tk()
root.title("メモ帳っぽいもの")
root.geometry("640x400")

filename = "mynote.txt"

def open_file ():
    if os.path.isfile(filename):
        with open(filename, "r",encoding="utf8") as file:
            txt.delete("1.0",END)
            txt.insert(END, file.read())
   

def save_file ():
    with open(filename, "w",encoding="utf8") as file:
        file.write(txt.get("1.0",END))

menu = Menu(root)
menu_file = Menu(menu, tearoff=0)
menu_file.add_command(label = "開く", command=open_file)
menu_file.add_command(label = "保存", command=save_file)
menu_file.add_separator()
menu_file.add_command(label = "終了", command=root.quit)
menu.add_cascade(label="ファイル", menu=menu_file)

menu.add_cascade(label="編集")
menu.add_cascade(label="書式")
menu.add_cascade(label="表示")
menu.add_cascade(label="ヘルプ")

#スクロールバー
scrollbar = Scrollbar(root)
scrollbar.pack(side="right",fill="y")

txt = Text(root, yscrollcommand=scrollbar.set)
txt.pack(side="left",fill="both",expand = True)

scrollbar.config(command=txt.yview)

root.config(menu=menu)
root.mainloop()
```

### 実行結果
![image.png](https://files.steempeak.com/file/steempeak/yasu/EeOdVi1Q-image.png)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 5 others
properties (23)
post_id87,751,684
authoryasu
permlinkma4xc-python
categoryhive-101145
json_metadata{"tags":["jp","marlians","zzan","python","sct-jp","sct-freeboard","mini","dblog","sct"],"image":["https:\/\/files.steempeak.com\/file\/steempeak\/yasu\/EeOdVi1Q-image.png"],"app":"steemcoinpan\/0.1","format":"markdown","canonical_url":"https:\/\/www.steemcoinpan.com\/@yasu\/ma4xc-python","users":["yasu"],"links":["https:\/\/repl.it\/"]}
created2020-09-30 02:03:48
last_update2020-09-30 02:08:21
depth0
children1
net_rshares59,276,123,267,242
last_payout2020-10-07 02:03:48
cashout_time1969-12-31 23:59:59
total_payout_value10.408 SBD
curator_payout_value9.802 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,358
author_reputation1,246,107,630,900,892
root_title"[Python] メモ帳っぽいもの作ってみました"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (69)
@sct.krwp ·
@yasu transfered 0.5 KRWP to @krwp.burn. voting percent : 5.62%, voting power : 62.55%, steem power : 1926827.97, STU KRW : 1200. 
@yasu staking status : 250 KRWP
                                @yasu limit for KRWP voting service : 0.5 KRWP (rate : 0.002)
                                What you sent : 0.5 KRWP [47305629 - 47e416b901ab6e91d3dc442314273d5a3087f3e2]
properties (22)
post_id87,751,728
authorsct.krwp
permlinkre--ma4xc-python-20200930t021051311z
categoryhive-101145
json_metadata{"tags":["jp","marlians","zzan","python","sct-jp","sct-freeboard","mini","dblog","sct"]}
created2020-09-30 02:10:57
last_update2020-09-30 02:10:57
depth1
children0
net_rshares0
last_payout2020-10-07 02:10:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length367
author_reputation10,000,000,000,000
root_title"[Python] メモ帳っぽいもの作ってみました"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000