プログラミングを始めたばかりの初心者です。
初めての質問なのでいろいろと伝わりにくかったりおかしなところがあってすみません...
実現したいこと
dir_path の部分をtkinterで作ったボタンで切り替えたい。
該当のソースコード
Python
1def Test(): 2 directory = Path.home()/dir_path 3 file_type = ('png',) 4 for type in file_type: 5 (Path(directory)/type).mkdir(exist_ok=True) 6 p = Path(directory).glob('*.' + type) 7 for f in p: 8 f.rename(Path(directory)/type/f.name)
試したこと
x = 1の部分をボタンに関連付けた A で0に変更しdir_testの'Downloads'を呼び出そうとしたが上手くいかなかった。
実行すると1で呼び出されるDocumentsで処理が実行されてしまう。
python
1一部抜粋 2 3import tkinter 4from pathlib import Path 5 6~ 7#ボタン123設定 8~ 9 10dir_test = ['Downloads','Documents'] 11x = 1 12dir_path = dir_test[x] 13 14def A(): 15 global x 16 x = 0 17 18def B(): 19 global x 20 x = 1 21 22def Test(): 23 global dir_path 24 directory = Path.home()/dir_path 25 file_type = ('png',) 26 for type in file_type: 27 (Path(directory)/type).mkdir(exist_ok=True) 28 p = Path(directory).glob('*.' + type) 29 for f in p: 30 f.rename(Path(directory)/type/f.name) 31 32button1['command'] = A 33button2['command'] = B 34button3['command'] = Test 35 36root.mainloop() 37
補足情報(FW/ツールのバージョンなど)
Python3.7

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/23 13:02
2018/08/23 13:05
2018/08/23 13:13 編集
2018/08/23 13:17
2018/08/23 16:24
2018/08/23 22:45
2018/08/23 22:49
2018/08/24 00:21
2018/08/24 00:48
2018/08/24 01:37