timetracker.py 880 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. from PyQt5 import QtCore, QtGui, QtWidgets
  3. from PyQt5.QtWidgets import QApplication, QMainWindow
  4. import sys
  5. class MyWindow(QMainWindow):
  6. def __init__(self):
  7. super(MyWindow, self).__init__()
  8. self.setGeometry(0, 0, 300, 300)
  9. self.setWindowTitle("Time Tracker")
  10. self.initUI()
  11. def initUI(self):
  12. self.label = QtWidgets.QLabel(self)
  13. self.label.setText("my first label!")
  14. self.label.move(50, 50)
  15. self.b1 = QtWidgets.QPushButton(self)
  16. self.b1.setText("Click me")
  17. self.b1.clicked.connect(self.clicked)
  18. def clicked(self):
  19. self.label.setText("you pressed the button")
  20. self.update()
  21. def update(self):
  22. self.label.adjustSize()
  23. def window():
  24. app = QApplication(sys.argv)
  25. win = MyWindow()
  26. win.show()
  27. sys.exit(app.exec_())
  28. window()