Python Forum
[PyQt] Push Button issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Push Button issue
#2
You should give you widgets names that indicate what they do like "start_button" or "time_display". You should definitely rename class Window to something like class Stopwatch. Good names go a long way in making programs easy to understand.

After you create the start_button you need to bind it to a function. I'm going to write a new function named "start_timer" (good names make programming easier). start_timer() is going to start the timer. It should reset the tick counter and start the timer. Binding the button to the function is as simple as:
self.start_button.click.connect(self.start_timer)
I start writing the "start_timer()" func. Hey, where is the timer? If you write a stopwatch class it should have a timer somewhere. Add some code to the __init__ method to create a timer (with a good name like "timer") and bind it to the function that updates time. Binding the button click to the start_time function is as simple as:
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_time)
Now I need a "update_time()" function. I see your code has a function named "local_button_handler" that does the counting and updates the time labels. Let's rename that to "update_time". Getting pretty close to making this thing work.

Let's review. Pressing the start_button calls start_timer(). start_timer() starts the timer running. Every ten milliseconds the timer calls update_time(). update_time() increments the tick counters and updates the time labels.

Now all you need is a way to stop the timer.
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 1,077 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,739 May-25-2023, 07:37 PM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,135 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Windows GUI with push buttons to launch python scripts drifterf 7 4,354 Jul-17-2019, 05:34 PM
Last Post: Yoriz
  Text after push button chano 13 5,655 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,816 Oct-30-2018, 05:09 AM
Last Post: bhargavbn
  [Tkinter] Selected radio button in push button in Tkinter prashantfunde91 1 11,919 Jun-22-2017, 05:27 PM
Last Post: DeaD_EyE
  PyQt4 get text from line edit into label on button push iFunKtion 2 21,940 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