它运行,但是在操作期间发生0xC0000409错误

发布于 2025-02-13 06:48:42 字数 1576 浏览 0 评论 0原文

我正在练习一个读取和显示Excel文件的程序 尝试提出整个代码。 我正在使用Python 3.9,Pycharm, PYQT5-5.15.7

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QHeaderView, QHBoxLayout, QVBoxLayout, QPushButton
from PyQt5.QtCore import Qt
import pandas as pd
from pympler import muppy
all_objects = muppy.get_objects()

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.window_width, self.window_height = 700, 500
        self.resize(self.window_width, self.window_height)

        layout = QVBoxLayout()
        self.setLayout(layout)

        self.table = QTableWidget()
        layout.addWidget(self.table)

        self.button = QPushButton('&load Data')
        self.button.clicked.connect(lambda _, xl_path=excel_file_patch, sheet_name=worksheet_name: self.loadExcelData(xl_path, sheet_name))
        layout.addWidget(self.button)

    def loadExcelData(self, excel_file_dir, worksheet_name):
        df = pd.read_excel(excel_file_dir, worksheet_name)
        if df.size == 0:
            return super.loadExcelData(excel_file_dir, worksheet_name)

        df.fillna('', inplace=True)
        self.table.setRowCount(df.shape[0])
        self.table.setColumnCount(df.shape[0])
        self.table.setHorizontalHeaderLabels(df.columns)

if __name__ == '__main__':

    excel_file_patch = 'data.xlsx'
    worksheet_name = 'Sales'

    app = QApplication(sys.argv)
    myApp = MyApp()
    myApp.show()

    try:
        sys.exit(app.exec())
    except SystemExit:
        print('closing Window...')

I'm practicing a program that reads and displays Excel files
Try raising the entire code.
I'm using Python 3.9, Pycharm,
PyQt5 - 5.15.7

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QHeaderView, QHBoxLayout, QVBoxLayout, QPushButton
from PyQt5.QtCore import Qt
import pandas as pd
from pympler import muppy
all_objects = muppy.get_objects()

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.window_width, self.window_height = 700, 500
        self.resize(self.window_width, self.window_height)

        layout = QVBoxLayout()
        self.setLayout(layout)

        self.table = QTableWidget()
        layout.addWidget(self.table)

        self.button = QPushButton('&load Data')
        self.button.clicked.connect(lambda _, xl_path=excel_file_patch, sheet_name=worksheet_name: self.loadExcelData(xl_path, sheet_name))
        layout.addWidget(self.button)

    def loadExcelData(self, excel_file_dir, worksheet_name):
        df = pd.read_excel(excel_file_dir, worksheet_name)
        if df.size == 0:
            return super.loadExcelData(excel_file_dir, worksheet_name)

        df.fillna('', inplace=True)
        self.table.setRowCount(df.shape[0])
        self.table.setColumnCount(df.shape[0])
        self.table.setHorizontalHeaderLabels(df.columns)

if __name__ == '__main__':

    excel_file_patch = 'data.xlsx'
    worksheet_name = 'Sales'

    app = QApplication(sys.argv)
    myApp = MyApp()
    myApp.show()

    try:
        sys.exit(app.exec())
    except SystemExit:
        print('closing Window...')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2025-02-20 06:48:42

在使用Python 3.9和Pycharm中使用基于TKINTER的应用程序时,我遇到了同样的问题。错误0xc000000409仅在我调试并在super().__ INT __()上放置一个断点时出现。

我没有在super().__ INT __()上设置断点,而是在初始化后移动了断点。这样,TKINTER事件循环启动正确,调试毫无问题地进行。

PS。我希望这将有助于某人避免3个小时的尝试解决这个问题:P

I encountered the same issue while working with a Tkinter-based application in Python 3.9 and Pycharm. The error 0xC0000409 appeared only when I was debugging and placed a breakpoint on super().__init__() during the initialization of a Tkinter window.

Instead of setting a breakpoint on super().__init__(), I moved the breakpoint just after the initialization. This way, the Tkinter event loop starts correctly, and the debugging proceeds without issues.

PS. I hope it will help someone to avoid 3 hours of trying to solve this (not)issue :P

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文