質問編集履歴
1
codeの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,103 @@
|
|
1
1
|
Pythonで同じファイルの中のhtmlファイルの指定の箇所を一斉に書き換えるGUIを書いていたのですが、その際Tkinterを使用して、どう書き換えるか指定するのにTextウィジェットを使ったところそれで表示されたテキストボックスの中に日本語を打ち込めません。調べたところTcl/Tkがだめと聞いてActive tclで最新版をインストールしたのですがそれでも上手くいきませんでした。どうしてでしょうか?そしてどうすれば上手くいきますでしょうか?
|
2
2
|
|
3
3
|
本当に素人質問でありますがご教授お願いします。
|
4
|
+
|
5
|
+
```python
|
6
|
+
|
7
|
+
# coding= utf-8
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
import sys
|
12
|
+
|
13
|
+
reload(sys)
|
14
|
+
|
15
|
+
sys.setdefaultencoding('utf-8')
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
import Tkinter as tk
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
root = tk.Tk()
|
28
|
+
|
29
|
+
root.title("実験")
|
30
|
+
|
31
|
+
root.geometry("640x480")
|
32
|
+
|
33
|
+
text_widget = tk.Text(root)
|
34
|
+
|
35
|
+
text_widget.grid()
|
36
|
+
|
37
|
+
get_start = tk.Entry(root)
|
38
|
+
|
39
|
+
get_start.grid()
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def paint():
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
s = open('./1.html', 'r')
|
52
|
+
|
53
|
+
f = s.read()
|
54
|
+
|
55
|
+
s.close()
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
start = get_start.get()
|
60
|
+
|
61
|
+
judge = start in f
|
62
|
+
|
63
|
+
if judge == False:
|
64
|
+
|
65
|
+
alert = tk.Message(root, text="タグが見つかりません")
|
66
|
+
|
67
|
+
alert.grid()
|
68
|
+
|
69
|
+
return
|
70
|
+
|
71
|
+
startN = f.find(start)
|
72
|
+
|
73
|
+
N = len(start) + 1
|
74
|
+
|
75
|
+
end = f.find('</header>') + N
|
76
|
+
|
77
|
+
moto = text_widget.get('1.0','end-1c')
|
78
|
+
|
79
|
+
change = f[startN:end]
|
80
|
+
|
81
|
+
res = f.replace(change,moto)
|
82
|
+
|
83
|
+
year = open('1.html','w')
|
84
|
+
|
85
|
+
year.write(res)
|
86
|
+
|
87
|
+
year.close()
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
go_button = tk.Button(root,text = 'go', command = paint)
|
94
|
+
|
95
|
+
go_button.grid()
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
root.mainloop()
|
102
|
+
|
103
|
+
```
|