аватар question@mail.ru · 01.01.1970 03:00

How to compile the module.py in the executable .exe file with a picture?

I have a script on pyqt5 , and it contains pictures,
but after compilation .py in .exe

how put the picture in the script so that the script and photos are not in different places?

аватар answer@mail.ru · 01.01.1970 03:00
  • Create a resource file for example res_1.qrc

      & Lt; RCC & GT;  & lt; qressource prefix =  & gt;  & lt; file & gt; images/head.jpg & lt;/file & gt; ; ; ; & lt;/qressource & gt;  & lt;/rcc & gt;     

    we assume that the picture head.jpg is located in the directory of images ( images/head.jpg )

  • download the image from the resource file:

    the command pyrcc5 res_1.qrc -o -o res_1_rc.py

    This method is to convert the res_1.qrc file to the res_1_rc.py all picture in res_1_rc.py

  • write main.py


       import  sys  from  pyqtgui  Import  qpixmap, Qmovo  from  pyqt5.qtwidgets  import  qpplication, QHboxlayout, Qlabel  Import  res_1_rc # Here we import our image    class   idageView  ( qwidget ):   def   __ init __  ( self, *args, ** kwargs ):   super  (imgeview, self) .__ Init __ (*arg, ** kwargs)  layout = qhboxlayout (self)  # load the image of the resource file   # The PyrcCC5 Res_1.QRC -o Res_1_rc.py   # "method is to convert the Res.QRC file to res_1_rc.py   file Layout.addwidget (Qlabel (Self, pixmap = qpixmap ( "" "" "" "" "" "" "" "" "" "" " res_1_rc.py    if  __name__ ==  "__ main __" ":  app = qapplication (sys.argv)  w = imageView () W.Resize ( 600 ,  python main.py  

  • Latest

    Similar