回答編集履歴
1
修正
test
CHANGED
@@ -72,6 +72,90 @@
|
|
72
72
|
|
73
73
|
news.set(item.string)
|
74
74
|
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
ベストではないかもしれませんが、だいぶマシになった感のあるコード全体が以下です。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```python
|
84
|
+
|
85
|
+
import time
|
86
|
+
|
87
|
+
from tkinter import *
|
88
|
+
|
89
|
+
import urllib.request
|
90
|
+
|
91
|
+
from bs4 import BeautifulSoup
|
92
|
+
|
93
|
+
import threading
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
NewsURL = "https://news.yahoo.co.jp/pickup/rss.xml"
|
98
|
+
|
99
|
+
def get_news():
|
100
|
+
|
101
|
+
response = urllib.request.urlopen(NewsURL)
|
102
|
+
|
103
|
+
html = BeautifulSoup(response, 'html.parser')
|
104
|
+
|
105
|
+
topics = html.find_all("title")
|
106
|
+
|
107
|
+
link = html.find_all("link")
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
news_title.set(topics[0].string)
|
112
|
+
|
113
|
+
for news, item in zip(news_list, topics[1:]):
|
114
|
+
|
115
|
+
news.set(item.string)
|
116
|
+
|
117
|
+
|
118
|
+
|
75
119
|
time.sleep(3600)
|
76
120
|
|
121
|
+
|
122
|
+
|
123
|
+
flg = threading.Event()
|
124
|
+
|
125
|
+
flg.set()
|
126
|
+
|
127
|
+
root = Tk()
|
128
|
+
|
129
|
+
root.attributes("-fullscreen", True)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
news_title = StringVar()
|
136
|
+
|
137
|
+
news_list = [StringVar() for _ in range(5)]
|
138
|
+
|
139
|
+
for news in news_list:
|
140
|
+
|
141
|
+
news.set("取得中")
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
Label(root,textvariable = news_title).pack()
|
146
|
+
|
147
|
+
for news in news_list:
|
148
|
+
|
149
|
+
Label(root, textvariable=news).pack()
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
t2 = threading.Thread(target = get_news)
|
154
|
+
|
155
|
+
t2.start()
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
root.mainloop()
|
160
|
+
|
77
161
|
```
|