Advertisement
Guest User

Untitled

a guest
Apr 10th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget, QTableWidgetItem, QVBoxLayout
  3. from PyQt5.QtGui import QIcon
  4. from PyQt5.QtCore import pyqtSlot
  5.  
  6.  
  7. class App(QWidget):
  8.  
  9.     def __init__(self):
  10.         super().__init__()
  11.         self.title = 'Tabliczka mnozenia'
  12.         self.left = 0
  13.         self.top = 0
  14.         self.width = 1200
  15.         self.height = 350
  16.         self.initUI()
  17.  
  18.     def initUI(self):
  19.         self.setWindowTitle(self.title)
  20.         self.setGeometry(self.left, self.top, self.width, self.height)
  21.  
  22.         self.createTable()
  23.  
  24.         # Add box layout, add table to box layout and add box layout to widget
  25.         self.layout = QVBoxLayout()
  26.         self.layout.addWidget(self.tableWidget)
  27.         self.setLayout(self.layout)
  28.  
  29.         # Show widget
  30.         self.show()
  31.  
  32.     def createTable(self):
  33.         # Create table
  34.         self.tableWidget = QTableWidget()
  35.         self.tableWidget.setRowCount(10)
  36.         self.tableWidget.setColumnCount(10)
  37.         self.tableWidget.move(0, 0)
  38.         self.tabliczka()
  39.  
  40.         # table selection change
  41.         self.tableWidget.doubleClicked.connect(self.on_click)
  42.  
  43.     def tabliczka(self):
  44.         for x in range(10):
  45.             for y in range(10):
  46.                 wynik = (x+1)*(y+1)
  47.                 self.tableWidget.setItem(x,y, QTableWidgetItem(str(wynik)))
  48.  
  49.     @pyqtSlot()
  50.     def on_click(self):
  51.         print("\n")
  52.         for currentQTableWidgetItem in self.tableWidget.selectedItems():
  53.             print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
  54.  
  55.  
  56. if __name__ == '__main__':
  57.     app = QApplication(sys.argv)
  58.     ex = App()
  59.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement