python pyinstaller 加载ui路径方法

yipeiwu_com6年前Python基础

如下所示:

class Login(QMainWindow):
  """登录窗口"""
  global status_s
  global connect_signal
  def __init__(self, *args):
    super(Login, self).__init__(*args)
    
    if getattr(sys,'frozen',False):
      bundle_dir = sys._MEIPASS
    else:
      bundle_dir = os.path.dirname(os.path.abspath(__file__))
    loadUi(bundle_dir+'\set_controller.ui', self) 

使用pyinstaller进行封装时,使用语句:

不带命令行界面 pyinstaller -w -F --add-data="set_controller.ui;." .\jiaben.py 

带命令行界面    pyinstaller -c -F --add-data="set_controller.ui;." .\jiaben.py 

添加icon图标时,在spec文件中添加,然后运行pyinstaller **.spec

以上这篇python pyinstaller 加载ui路径方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解Python locals()的陷阱

在工作中, 有时候会遇到一种情况: 动态地进行变量赋值, 不管是局部变量还是全局变量, 在我们绞尽脑汁的时候, Python已经为我们解决了这个问题. Python的命名空间通过一种字典...

python一键升级所有pip package的方法

pip_ungrade_all.py代码如下: # -*- coding: utf-8 -*- import pip from subprocess import call f...

python自动生成model文件过程详解

生成方式 Python中想要自动生成 model文件可以通过 sqlacodegen这个命令来生成对应的model文件 sqlacodegen 你可以通过pip去安装: pip i...

django将数组传递给前台模板的方法

将数组传递给前台模板: 1. def modifyBtn(req,modifyip): print modifyip conn= MySQLdb.connect(...

Python selenium实现微博自动登录的示例代码

Python selenium实现微博自动登录的示例代码

(一)编程环境 操作系统:Win 10 编程语言:Python 3.6 (二)安装selenium 这里使用selenium实现。 如果没有安装过python的seleni...