Junissen
Posted on November 28, 2024
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:
- Files that complement the main project, namely libraries and XML describing the graphical/integration structure (MySQL including)
- The terminal usually stores the path to the executable file in the computer's system storage, as in ArchLinux. The assembly itself pulls up the necessary libraries if they are standard/you placed them there
- As a result, make all the necessary extensions in advance by adding them to the root path
- Add the path to the admin's security settings, as the security system sometimes ignores undescribed exceptions explicitly (do it in the settings 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.
Posted on November 28, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.