from one import Ui_Form
import sys
import os
from PyQt5.Qt import *
# BASE_PAH = os.path.dirname(os.path.abspath(__file__))
BASE_PAH = os.path.dirname(os.path.realpath(sys.argv[0]))#当打包为单文件时,这样写。要不然文件加载不了
# print(BASE_PAH)
class Window(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
def btn_event(self):
with open(os.path.join(BASE_PAH, 'resource', 'stu.txt')) as f:
data = f.read()
QMessageBox.warning(self,'ok',data)
def re_btn_connect(self):
self.pushButton.clicked.connect(self.btn_event)
def dis_connect(self):
self.pushButton.clicked.disconnect(self.btn_event)
if __name__ == '__main__':
import sys
app=QApplication(sys.argv)
win=Window()
win.show()
python单文件打包
于 2023-06-29 13:14:29 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)