2017-10-07 43 views
0

我添加代碼到我的應用程序打開圖像序列與兩個按鈕prev和next。 我怎麼可以設置下一個按鈕每秒點擊,例如播放序列?PyQt5循環圖像序列automaticaly

def nextitem(self): 
    self.listWidget.sortItems() 
    #a = self.choice2.text() 
    count = self.listWidget.count() 
    cur = self.listWidget.currentRow() 
    self.listWidget.setCurrentRow(cur+1) 
    if (cur+1) == count: 
     self.listWidget.setCurrentRow(0) 
    if len(self.choice2.text()) > 0: 
     tex = self.listWidget.currentItem().text() 
     a = self.video_choice_2.setText(tex) 
    self.playVideo2() 

enter image description here

UPDATE 我發現在論壇的功能和它的工作,但我不能停止動畫或做別的。

import time 
    repeat_time = 0.3 
    while True: 
     start_time = time.time() 
     self.nextitem() 
     time.sleep(max(repeat_time - (time.time() - start_time), 0.0)) 

回答

0

您不想使用time.sleep,因爲它會鎖定進程。改爲使用PyQt5.QtCore中的QTimer。 Google有大量的關於如何使用QTimer的例子。

+0

感謝您的信息;我會搜索一下 – seghier

+1

謝謝;我找到一個很好的例子:http://nullege.com/codes/show/[email protected]@[email protected]@[email protected]@[email protected]@bubbleswidget.py/126/PyQt5.QtCore.QTimer – seghier

0

我找到解決方案,它的工作良好,但當我點擊播放按鈕兩次或多次速度增加,我不能停止動畫。

def playSeq(self): 
    self.animation_timer = QTimer(self) 
    self.animation_timer.setSingleShot(False) 
    self.animation_timer.timeout.connect(self.nextitem) 
    self.animation_timer.start(300) 

UPDATE:問題解決 當我點擊它總是叫Qtimer之前,但現在它調用start僅

self.animation_timer = QTimer(self) 
    self.animation_timer.setSingleShot(False) 
    self.animation_timer.timeout.connect(self.nextitem) 
def playSeq(self):  
    self.animation_timer.start(300) 
+0

如果你有另外一個問題,請點擊[Ask Question](// stackoverflow.com/questions/ask)按鈕。 – ekhumoro

+0

這是同一主題中的另一個問題;爲什麼我需要再問一次,而不是一個人 - 我確信 - 會像你的評論一樣評論:不要問同樣的問題,請如果你忍不住不要評論 – seghier

+0

如果你有一個新的問題,請問問通過點擊[Ask Question](https://stackoverflow.com/questions/ask)按鈕。如果有助於提供上下文,請包含此問題的鏈接。 - [來自評論](/ review/low-quality-posts/17560229) –