(三)我的第一个GUI程序,生成EXE文件出现的问题

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42691768/article/details/81045413

1. 在Pycharm中,新建项目FirstGUI

2. 调用Qt设计师(designer.exe)。

利用Qt设计一个窗口的ui文件(First_ui.ui)

3.调用PyUIC5,将First_ui.ui文件转为First_ui.py文件。

生成的First_ui.py文件如下:

4.新建FirstGUI.py。建立主程序,打开窗口。

 

import sys

from PyQt5.QtWidgets import *
import First_ui

if __name__ == "__main__":
    app =  QApplication(sys.argv)
    widget = QMainWindow()
    form = First_ui.Ui_MainWindow()
    form.setupUi(widget)
    widget.show()
    sys.exit(app.exec_())

因为Qt Designer默认继承的object类,不提供show()显示方法,所以我们生成一个QMainWindowt对象来重载我们设计的Ui_MainWindow类,达到显示效果。

5.测试程序。可能会出现如下错误:(本人用两台机测试时,一台可以直接在Pycharm中运行测试成功,另一台测试出错,不知何原因。知道是Pycharm配置原因,但是不知哪个位置配置错了。哪位大侠可以指正下?)

This application failed to start because it could not find or load the Qt platform plugin "windows" in "".

Reinstalling the application may fix this problem.

这是因为缺少运行库,需要把Python目录中的

Library\plugins\platforms

Library\bin\libEGL.dll

复制到venv\Scripts目录下可以解决。

5.生成EXE文件。直接运行FirstGUI.exe,会出现上面的错误。将缺少的运行库,

Library\plugins\platforms

Library\bin\libEGL.dll

复制到当前目录下,测试成功。

展开阅读全文

生成exe文件出现问题

02-28

各位大侠:rnrn小弟的测试的过程中,rn需要上传文件过数据库.rnpublic class DBFactory rn private static String CLASSNAME =rn "com.microsoft.jdbc.sqlserver.SQLServerDriver";rn private static String databaseURL =rn "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DatabaseName";rn private static String user = "sa";rnrn //private static String password = "";rn private static String password = "";rnrn private static DatabaseDAO factorydao = null;rnrn //是否是第一次联接,做报错提示使用rn public static boolean isfirstcon = true;rnrn public static boolean stop = false;rnrn static ConnectionFactory cf = null;rn..........rnrn测试程序运行没有问题,但是生成exe文件后,运行exe文件rn就出现如下问题.提示是:rnC:\Documents and Settings\hua\桌面\11111.txtrnconnection factory 创建!rnjava.lang.ClassNotFoundException: com/microsoft/jdbc/sqlserver/SQLServerDriverrn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Unknown Source)rn at util.connectionpool._Connection.(_Connection.java:44)rn at util.connectionpool._Connection.getConnection(_Connection.java:117)rn at util.connectionpool.ConnectionFactory.(ConnectionFactory.java:71)rn at util.DBFactory.getDao(DBFactory.java:82)rn at dao.Luckdao.GenerateLuckyTable(Luckdao.java:44)rn at ris_lucky.ris_luckyFrame.jButtonupload_actionPerformed(ris_luckyFrame.java:158)rn at ris_lucky.ris_luckyFrame_jButtonupload_actionAdapter.actionPerformed(ris_luckyFrame.java:rn227)rn at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)rn at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)rn at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)rn at javax.swing.DefaultButtonModel.setPressed(Unknown Source)rn at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)rn at java.awt.Component.processMouseEvent(Unknown Source)rn at javax.swing.JComponent.processMouseEvent(Unknown Source)rn at java.awt.Component.processEvent(Unknown Source)rn at java.awt.Container.processEvent(Unknown Source)rn at java.awt.Component.dispatchEventImpl(Unknown Source)rn at java.awt.Container.dispatchEventImpl(Unknown Source)rn at java.awt.Component.dispatchEvent(Unknown Source)rn at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)rn at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)rn at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)rn at java.awt.Container.dispatchEventImpl(Unknown Source)rn at java.awt.Window.dispatchEventImpl(Unknown Source)rn at java.awt.Component.dispatchEvent(Unknown Source)rn at java.awt.EventQueue.dispatchEvent(Unknown Source)rn at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)rn at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)rn at java.awt.EventDispatchThread.pumpEvents(Unknown Source)rn at java.awt.EventDispatchThread.pumpEvents(Unknown Source)rn at java.awt.EventDispatchThread.run(Unknown Source)rn.......rnrn请大侠们请教/谢谢 论坛

没有更多推荐了,返回首页