Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:36:23+00:00 2026-06-05T01:36:23+00:00

This is the same script i used in my local system where it work

  • 0

This is the same script i used in my local system where it work exactly. The same script is using in another location where its also a same system same setup. But not working.

I can not find anything wrong myself on this. Any idea if its a Python Bug?

What it does runs for 24/7 and shows a simple Gui before 9AM and after 3PM (PC has 24 hour time mode not AM or PM) . But its not doing in long run. (in my local system its doing exactly). How do i resolve this?

import sys
import datetime
import time
from PyQt4 import QtCore, QtGui

class Main(QtGui.QMainWindow):
  def __init__(self, parent=None):
    super(Main, self).__init__(parent) 
    flags  = QtCore.Qt.Window
    flags |= QtCore.Qt.FramelessWindowHint
    flags |= QtCore.Qt.WindowStaysOnTopHint
    self.setWindowFlags(flags)     
    self.b = QtGui.QPushButton("9/15 open", self, clicked=self.close)
    self.c = QtGui.QLabel("", self)

  def myRun(self):
    while True:
      time.sleep(2)
      print "[Debug]: " + self.showNowHour() + " " + self.showNowMinute()      
      hour = int(self.showNowHour())
      minute = int(self.showNowMinute())
      if (hour>8 and hour<15):
        print "is open"
        self.hide()
      else:
        print "is close"
        self.show()

  def showNowHour(self):
    now = datetime.datetime.now()
    now = now.strftime("%H")    
    return now

  def showNowMinute(self):
    now = datetime.datetime.now()
    return now.strftime("%M")

if __name__ == "__main__":
  app=QtGui.QApplication(sys.argv)
  myapp=Main()
  myapp.setStyleSheet("background-color: rgb(85, 0, 0);")
  thread = QtCore.QThread()
  thread.run = lambda myapp=myapp: myapp.myRun()
  thread.start()    
  sys.exit(app.exec_())

Follow up:

  1 import sys
  2 import datetime
  3 import time
  4 from PyQt4 import QtCore, QtGui
  5 
  6 class Main(QtGui.QMainWindow):
  7   def __init__(self, parent=None):
  8     super(Main, self).__init__(parent)
  9     self.b = QtGui.QPushButton("exit", self, clicked=self.close)
 10 
 11   def showNowHour(self):
 12     return datetime.datetime.now().strftime("%H")
 13 
 14   def showNowMinute(self):
 15     return datetime.datetime.now().strftime("%M")
 16 
 17   def myRun(self):
 18     while True:
 19       time.sleep(2)
 20       hour = int(self.showNowHour())
 21       minute = int(self.showNowMinute())
 22       print "[Debug]: " + str(hour) + " " + str(minute)
 23       if (hour>8 and hour<15):
 24         print "is open"
 25       else:
 26         print "is close"
 27 
 28 if __name__ == "__main__":
 29   app=QtGui.QApplication(sys.argv)
 30   myapp=Main()
 31   myapp.show()
 32   thread = QtCore.QThread()
 33   thread.run = lambda myapp=myapp: myapp.myRun()
 34   thread.start()    
 35   app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
 36   sys.exit(app.exec_())
 37   while thread.isAlive():
 38     app.processEvents()
 39 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:36:25+00:00Added an answer on June 5, 2026 at 1:36 am

    This possibly fails because you are calling GUI methods from a different thread. You should always perform GUI calls within the main thread (aka “GUI thread”), otherwise it is easy to run into problems.

    Instead of a thread which sleeps for two seconds on every loop, replace it with a QTimer that fires every 2 seconds. Put something like this in your mainline:

    timer = QTimer()
    timer.timeout.connect(myapp.myPeriodicRun)  # connect the "timeout" signal
    timer.start(2000)  # call every 2 seconds
    

    In your Main class replace the myRun method with:

    def myPeriodicRun(self):
      print "[Debug]: " + self.showNowHour() + " " + self.showNowMinute()      
      hour = int(self.showNowHour())
      minute = int(self.showNowMinute())
      if (hour>8 and hour<15):
        print "is open"
        self.hide()
      else:
        print "is close"
        self.show()
    

    Isn’t it nice not to need threads!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one boggles my mind. I've used this same script (different targets of course)
I have roughly 12 computers that each have the same script on them. This
The upload script in this page is currently uploading the images to the same
I've seen the other post with pretty much this same question, but I don't
I am using this in Script Component In SSIS --> Microsoft.Office.Interop.Excel.Application objXL = new
I know this type of thing I want to do used to work in
I am currently using an image manipulation script to do some work on uploaded
I have a script which runs when the system boot first time. But that
I posted this same question on apple.stackexchange... maybe here it fits better. Does anyone
I've asked this same question with Python. Now I like to know if this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.