回答編集履歴
1
StringVar() を使ったサンプルコードを追加
test
CHANGED
@@ -33,3 +33,87 @@
|
|
33
33
|
main()
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
tk.StringVar() を使った例を示します。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```python
|
44
|
+
|
45
|
+
import os
|
46
|
+
|
47
|
+
import tkinter as tk
|
48
|
+
|
49
|
+
import tkinter.filedialog as filedialog
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def mail_checker(root):
|
54
|
+
|
55
|
+
root.title('メールチェッカー')
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
search_files = tk.StringVar()
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
tk.Label(root, text="メールを読み込んで必要な情報を出力します").pack()
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
frame1 = tk.Frame(root)
|
68
|
+
|
69
|
+
frame1.pack()
|
70
|
+
|
71
|
+
tk.Label(frame1, text="ファイル名").pack(side='left')
|
72
|
+
|
73
|
+
tk.Entry(frame1, textvariable=search_files).pack(side='left')
|
74
|
+
|
75
|
+
tk.Button(frame1, text='参照', command=lambda: search_files.set(select_files())).pack(side='left')
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
frame2 = tk.Frame(root)
|
80
|
+
|
81
|
+
frame2.pack()
|
82
|
+
|
83
|
+
tk.Button(frame2, text='はじめる', command=lambda: start(search_files.get())).pack(side='left')
|
84
|
+
|
85
|
+
tk.Button(frame2, text='Cancel', command=root.quit).pack(side='left')
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def select_files():
|
90
|
+
|
91
|
+
fTyp = [('', '*')]
|
92
|
+
|
93
|
+
iDir = os.path.abspath(os.path.dirname(__file__))
|
94
|
+
|
95
|
+
return filedialog.askopenfilenames(filetypes=fTyp, initialdir=iDir)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def start(files):
|
100
|
+
|
101
|
+
print(files)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
def main():
|
106
|
+
|
107
|
+
root = tk.Tk()
|
108
|
+
|
109
|
+
mail_checker(root)
|
110
|
+
|
111
|
+
root.mainloop()
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
if __name__ == '__main__':
|
116
|
+
|
117
|
+
main()
|
118
|
+
|
119
|
+
```
|