I'm trying to add a picture to a button in PyQt5 using stylesheet. It is working fine if I use an absolute path to the picture, but I need to use a relative path instead. I've tried the pythonic way (the commented out part), but it is not working probably because of the backslashes. I know about Qt resources but I don't understand how to use them. link
import os, sys
from PyQt5.QtWidgets import *
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
#scriptDir = os.path.dirname(os.path.realpath(__file__))
#pngloc = (scriptDir + os.path.sep + 'resources' + os.path.sep + 'min.png')
button1 = QPushButton("", self)
button1.setStyleSheet('QPushButton {'
'background-image: url(e:/new/resources/min.png);'
'}')
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())