Python Forum
[PyQt] Push Button issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Push Button issue
#5
Thanks again for your help and patience ! Made changes (see code below). Still doesn't work.

import sys

from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QGridLayout, QSizePolicy, QApplication

class Stopwatch(QWidget):

    def __init__(self, *args, **kwargs):

        self.timer = QTimer()
        self.timer.timeout.connect(self.update_time)


        def start_button(self):

            self.start_button.click.connect(self.start_timer)


        self.my_counter = 0
        self.my_counter1 = 0
        self.my_counter2 = 0


        QWidget.__init__(self, *args, **kwargs)

        self.label = QLabel(self)
        self.label1 = QLabel(self)
        self.label2 = QLabel(self)
        self.label.setText("00")
        self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setStyleSheet("QLabel {background-color: white; font-size: 30pt;}")


        self.label1 = QLabel(self)
        self.label1.setAlignment(Qt.AlignCenter)
        self.label1.setStyleSheet("QLabel {background-color: white; font-size: 30pt;}")
        self.label1.setText("00.")

        self.label2 = QLabel(self)
        self.label2.setAlignment(Qt.AlignCenter)
        self.label2.setStyleSheet("QLabel {background-color: pink; font-size: 30pt;}")
        self.label2.setText("00:")

        self.start_button = QPushButton(self)
        self.start_button.setStyleSheet("QPushButton {background-color: yellow; font-size: 15pt;}")
        self.start_button.setText("Start")

        self.layout = QGridLayout(self)
        self.layout.addWidget(self.label, 0, 4)
        self.layout.addWidget(self.label1, 0, 3)
        self.layout.addWidget(self.label2, 0, 2)
        self.layout.addWidget(self.start_button, 3, 3)

        self.setLayout(self.layout)
        self.show()
        

    def update_time(self):

        self.label.setText("%d" % self.my_counter)
        self.my_counter += 1

        if self.my_counter == 100:
            self.my_counter = 0
            self.my_counter1 += 1
            self.label1.setText("%d" % self.my_counter1 + ".")

            if self.my_counter1 == 60:
                self.label1.setText("00.")
                self.my_counter1 = 0
                self.my_counter2 += 1
                self.label2.setText("0"+"%d" % self.my_counter2 + ":")
            elif self.my_counter1  < 10:
                self.label1.setText("0" + "%d" % self.my_counter1 + ".")

        elif self.my_counter < 10:

            self.label.setText("0" +  "%d" % self.my_counter)

    def start_timer(self):

        self.timer.start(10)    
 

app = QApplication(sys.argv)
win = Stopwatch()
sys.exit(app.exec_())
Reply


Messages In This Thread
Push Button issue - by gvin47 - Apr-16-2020, 06:39 PM
RE: Push Button issue - by deanhystad - Apr-16-2020, 08:59 PM
RE: Push Button issue - by gvin47 - Apr-17-2020, 04:41 AM
RE: Push Button issue - by deanhystad - Apr-17-2020, 08:21 AM
RE: Push Button issue - by gvin47 - Apr-17-2020, 05:30 PM
RE: Push Button issue - by deanhystad - Apr-17-2020, 06:39 PM
RE: Push Button issue - by gvin47 - Apr-17-2020, 07:28 PM
RE: Push Button issue - by gvin47 - Apr-17-2020, 10:59 PM
RE: Push Button issue - by deanhystad - Apr-18-2020, 05:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 960 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,245 May-25-2023, 07:37 PM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,077 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Windows GUI with push buttons to launch python scripts drifterf 7 4,254 Jul-17-2019, 05:34 PM
Last Post: Yoriz
  Text after push button chano 13 5,516 Jul-05-2019, 03:10 PM
Last Post: Yoriz
  [PyQt] Close program using Push Button with the help of input from a Message Box bhargavbn 2 6,744 Oct-30-2018, 05:09 AM
Last Post: bhargavbn
  [Tkinter] Selected radio button in push button in Tkinter prashantfunde91 1 11,882 Jun-22-2017, 05:27 PM
Last Post: DeaD_EyE
  PyQt4 get text from line edit into label on button push iFunKtion 2 21,869 Feb-27-2017, 12:14 PM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020