回答編集履歴
1
a
test
CHANGED
@@ -125,3 +125,93 @@
|
|
125
125
|
sys.exit(app.exec_())
|
126
126
|
|
127
127
|
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
## 一定時間経過したら関数を呼ぶ
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
`QTimer.start(ミリ秒)` と開始すると、指定時間経過後に timeout シグナルが発行されるので、シグナルスロットで呼び出す関数を登録しておけば、一定時間後になにか処理するということが実現できます。
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
[QTimer](http://doc.qt.io/qt-5/qtimer.html)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```python
|
144
|
+
|
145
|
+
import sys
|
146
|
+
|
147
|
+
from PyQt5.QtWidgets import *
|
148
|
+
|
149
|
+
from PyQt5.QtGui import *
|
150
|
+
|
151
|
+
from PyQt5.QtCore import *
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
class MainWindow(QWidget):
|
156
|
+
|
157
|
+
def __init__(self):
|
158
|
+
|
159
|
+
super().__init__()
|
160
|
+
|
161
|
+
self.initUI()
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
def initUI(self):
|
166
|
+
|
167
|
+
self.setGeometry(100, 100, 640, 480)
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
pushButton = QPushButton("Click")
|
172
|
+
|
173
|
+
pushButton.clicked.connect(self.pushButtionClicked)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
layout = QVBoxLayout()
|
178
|
+
|
179
|
+
layout.addWidget(pushButton)
|
180
|
+
|
181
|
+
self.setLayout(layout)
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
self.show()
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def on_timeout(self,):
|
190
|
+
|
191
|
+
'''タイムアウトした場合に呼ばれる。
|
192
|
+
|
193
|
+
'''
|
194
|
+
|
195
|
+
QMessageBox.about(self, "Title", "Message")
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
def pushButtionClicked(self):
|
200
|
+
|
201
|
+
self.timer = QTimer(self)
|
202
|
+
|
203
|
+
self.timer.timeout.connect(self.on_timeout)
|
204
|
+
|
205
|
+
self.timer.start(3000)
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
if __name__ == '__main__':
|
210
|
+
|
211
|
+
app = QApplication(sys.argv)
|
212
|
+
|
213
|
+
ex = MainWindow()
|
214
|
+
|
215
|
+
sys.exit(app.exec_())
|
216
|
+
|
217
|
+
```
|