Connecting Python libraries is carried out similarly to the standard procedure, be it C /Java/others:
import sys import openpyxl from PyQt5 import QtWidgets from PyQt5.Qt import QTableWidgetItem from PyQt5.QtWidgets import ( QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QTableWidget, )
Due to the lack of a Python debugger, it is difficult to verify the correctness of the build and the presence of libraries. The command line (CLI) with operating system prompts is very helpful.
def appication(): app=QApplication(sys.argv) window = QMainWindow() window.setWindowTitle("Smart home") window.setGeometry(300, 250, 300, 200) window.show() sys.exit(app.exec_()) if __name__=="__main__": appication()
The .py file extension occurs where, when you run the file as a command in the terminal, the builder pulls from your project's location path:
lass MainWindow(QMainWindow): def __init__(self): super().__init__() self.setMinimumWidth(1200) self.setMinimumHeight(600) layout = QVBoxLayout() self.table = QTableWidget(self) self.table.setRowCount(4) self.table.setColumnCount(4) layout.addWidget(self.table) btn = QPushButton("Download") btn.clicked.connect(self.btn_click) layout.addWidget(btn) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) def btn_click(self): wb = load_workbook('./123.xlsx') # Get sheet names sheet = wb['Sheet1'] print(sheet.cell(row=2, column=1).value) for row in range(1, 5): for column in range(1, 5): item = QTableWidgetItem() item.setText(str(sheet.cell(row=row, column=column).value)) self.table.setItem(row-1, column-1, item) app = QApplication(sys.argv) window = MainWindow() window.show() app.exec()
I don’t really believe in graphical shells for the Python environment; more often than not, they complicate interaction with files. Proper installation of libraries with accompanying conventions makes it easier to interact with the code. The lighter the level and more primitive, the better. Evolution informs reality - not the other way around.
The above is the detailed content of .py extension convention. For more information, please follow other related articles on the PHP Chinese website!