Python count How many Clicks are in a second

前端 未结 2 1918
野的像风
野的像风 2021-01-21 04:21

Would someone mind helping me with this? I\'m trying to make a clicks per second test like this one on this website.

I\'ve tried many different things, but I couldn\'t f

2条回答
  •  庸人自扰
    2021-01-21 05:05

    You have to assign function to button

    from PyQt4 import QtGui
    import sys
    
    class MyWindow(QtGui.QWidget):
    
        def __init__(self, parent=None):
            super(MyWindow, self).__init__()
    
            self.clicks = 0
    
            self.vbox = QtGui.QVBoxLayout()
            self.setLayout(self.vbox)
    
            self.label = QtGui.QLabel(str(self.clicks), self)
            self.vbox.addWidget(self.label)
    
            self.button = QtGui.QPushButton("Click Me!", self)
            self.vbox.addWidget(self.button)
    
            # assign function to button 
            self.button.clicked.connect(self.on_click)
    
            self.show()
    
        def on_click(self):
            self.clicks += 1
            self.label.setText(str(self.clicks))
    
    app = QtGui.QApplication(sys.argv)
    win = MyWindow()
    app.exec_()
    

提交回复
热议问题