2013-08-12 1 views
0

나는이 코드 조각이 : 그것은 예 버튼이 후 처음 2 초 대기 추가를 누르면됩니다 무엇Python, PySide는 전체 프로그램을 멈추지 않고 잠을 자고 있습니까?

self.connect(self.Yes_button,SIGNAL('clicked()'),self.Yes_pressed) 
self.connect(self.No_button,SIGNAL('clicked()'),self.No_pressed) 

def Yes_pressed(self): 
    self.Box.append("Hello") 
    time.sleep(2) 
    self.Box.append("Text2") 

안녕하세요 텍스트 2 (상자는 QTextBrowser() 객체이다) 내가 어떻게 만들 수 모두 그래서 하나 추가, 2 초 기다리고 대신 다른 하나를 추가 할까? 이 간단한 해결책이 있습니까?

+0

시도하고, 작품 도니는 다르게 – joaoricardo000

답변

2

pyqt'sQtimer을 사용하면 다음과 같이 할 수 있습니다. 보다 구체적으로 singleShot

설정 : QTimer.singleShot (int msec, QObject receiver, SLOT()SLOT() member)

QtCore.QTimer.singleShot(1000, lambda: self.Box.append("Text2")) #1000 milliseconds = 1 second 

아니면 사건이 구현 시도 할 수 있습니다 : 당신은 아마 이런 식으로 뭔가를 할 수있는 2

self.timerScreen = QTimer() 
    self.timerScreen.setInterval(1000) #1000 milliseconds = 1 second 
    self.timerScreen.setSingleShot(True) 
    self.timerScreen.timeout.connect(self.Box.append("Text2")) 

파트를하지만, 추천하지 않습니다.

01 23,516,
def testSleep(self): 
    self.lineEdit.setText('Start') 
    QtCore.QTimer.singleShot(10000, lambda: self.Box.append("Text2")) 
    QtCore.QTimer.singleShot(10000,lambda: self.timerEvent) 


def timerEvent(self): 
    QtCore.QTimer.singleShot(10000, lambda: self.Box.append("Text3")) 

당신은 그냥이 같은 일을 더 낫다 : 수면 전에 self.update()를 호출하는

x = 10000 #or whatever number 
QtCore.QTimer.singleShot(10000 + x, lambda: self.Box.append("Text3")) 
+0

내가 그러나보고 난 그 모든 여기에 문제가 있다면 말해 계산이 동시에 시작되므로 추가 할 때마다 X 초의 일시 중지가 필요합니다. 그래서 예를 들어 : QTimer.singleShot (10000, λ : self.Box.append ("텍스트 2")) QTimer.singleShot (10000, λ : self.Box.append ("텍스트 3")) 모두 프린트 10 초 후 나는 text3을 만들지 않고 10 초 간격으로하고 싶다. 3 20000 – Granitas

+0

기본적으로 text2와 text3 사이에서 함수가 호출 될 때마다 기본적으로'x + 10000'을 원한다. Thats easily, 그냥 내 편집을 확인하십시오. – enginefree

+0

@Granitas 나는 나의 대답을 편집했다. – enginefree

관련 문제