Created
August 6, 2017 00:43
-
-
Save eyllanesc/ec607bc96d9acd570a31c0041c59037e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtGui import * | |
from PyQt5.QtCore import * | |
from PyQt5.QtWidgets import * | |
import sys | |
class Widget(QWidget): | |
def __init__(self, parent=None): | |
QWidget.__init__(self, parent) | |
self.setLayout(QVBoxLayout()) | |
self.le = QLineEdit(":P", self) | |
self.le.setPlaceholderText("Value to be changed") | |
self.combo = QComboBox(self) | |
btn = QPushButton("Press Me to Change", self) | |
btn.clicked.connect(self.onClicked) | |
self.table = QTableWidget(self) | |
self.layout().addWidget(self.le) | |
self.layout().addWidget(self.combo) | |
self.layout().addWidget(btn) | |
self.layout().addWidget(self.table) | |
self.table.setRowCount(4) | |
self.table.setColumnCount(2) | |
for i in range(self.table.rowCount()): | |
for j in range(self.table.columnCount()): | |
self.table.setItem(i, j, QTableWidgetItem("Item ({},{})".format(i, j))) | |
self.combo.addItems(["{}, {}".format(i, j) for i in range(self.table.rowCount()) for j in range(self.table.columnCount())]) | |
def onClicked(self): | |
x, y = self.combo.currentText().split(",") | |
self.table.item(int(x), int(y)).setText(self.le.text()) | |
def main(): | |
app = QApplication(sys.argv) | |
widget = Widget() | |
widget.show() | |
return app.exec_() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment