teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードを追加

2019/11/18 13:24

投稿

id_nazonazo
id_nazonazo

スコア22

title CHANGED
File without changes
body CHANGED
@@ -13,4 +13,63 @@
13
13
  それとも(1)から(2)へもっとかんたんにデータを渡す方法がありますか?
14
14
 
15
15
  アドバイスなどいただけたらと思います。
16
- よろしくおねがいします。
16
+ よろしくおねがいします。
17
+
18
+
19
+ ```Python
20
+
21
+ import os
22
+ import tkinter as tk
23
+ import tkinter.messagebox as tkm
24
+ import tkinter.filedialog as tkf
25
+ import tempfile
26
+
27
+ def getFiDir(self, event=None):
28
+ h_dir0 = os.path.dirname(__file__)
29
+ h_fileDir = tkf.askopenfilename(filetypes=[("","*.txt")], initialdir=h_dir0 )
30
+ h_mojiichi = h_fileDir.rfind('/')
31
+ h_file_name = h_fileDir[h_mojiichi + 1:]
32
+ h_file_name = h_file_name [0:h_file_name.rfind('.')]
33
+ field1.config(text=str(h_file_name))
34
+ field2.delete(0, tk.END)
35
+ field2.insert(0, h_fileDir)
36
+ h_clip = h_file_name +"\n" + h_fileDir
37
+
38
+ def test():
39
+ # h_clip を使用したい。
40
+
41
+ # __ウインドウ______________
42
+
43
+ if __name__ == '__main__':
44
+ #
45
+ root = tk.Tk()
46
+ root.geometry('600x200+300+180')
47
+ root.title('Convert text to html')
48
+ f1 = tk.Frame(root, bg='#eee', padx=10, pady=10)
49
+ f1.pack(fill='x', side='top')
50
+ f2 = tk.Frame(root, bg='#eee', padx=10, pady=10)
51
+ f2.pack(fill='x', side='top')
52
+ f3 = tk.Frame(root, bg='#eee', padx=10, pady=20)
53
+ f3.pack(fill='x', side='top')
54
+ #
55
+ w1, w2, w3 = 12, 36, 8
56
+ l1 = tk.Label(f1, text=u'ファイル名',anchor='w', width=w1)
57
+ l1.pack(side='left')
58
+ field1 = tk.Label(f1, padx=5, anchor='w', width=w2)
59
+ field1.pack(side='left')
60
+ b1 = tk.Button(f1, text=u'参照', pady=1, width=w3)
61
+ b1.bind('<ButtonRelease-1>', ins_wAction.m_getFiDir)
62
+ b1.pack(side='left')
63
+ l2 = tk.Label(f2, text=u'ディレクトリ:', anchor='w', width=w1)
64
+ l2.pack(side='left')
65
+ field2 = tk.Entry(f2, bg='#efefef', width=w2+8)
66
+ field2.pack(side='left')
67
+ l2_2 = tk.Label(f2, text=u'', width=1)
68
+ l2_2.pack(side='left')
69
+ b_convert = tk.Button(f3, text='convert', padx=20, pady=2, width=w3)
70
+ b_convert.bind('<ButtonRelease-1>', test )
71
+ b_convert.pack()
72
+ #.
73
+ root.mainloop()
74
+
75
+ ```