Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

python - Can't set background image fixed/still

I'm working on tic tac toe game with GUI in Python and I'm using PyQt5. I'm struggling with setting my background image in one place and not letting it move at all. I tried using
self.window.setStyleSheet("background-image: url(tictactoe.png); background-attachment: fixed; background-repeat: no-repeat; background-position: center; background-color: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #ffc982, stop:1 #ff9982);") but any option is not working for me. Whevener I add button, label, or anything my image is moving with it. Here is rest of the code:

class App(QMainWindow):
def __init__(self):
    super().__init__()
    self.setWindowTitle("Tic Tac Toe")
    self.app = QApplication([])
    self.window = QWidget()

    
    self.window.setGeometry(800,350,800,800)
    self.layout = QVBoxLayout()
    self.empty = QLabel('')
    self.buttonstart = QPushButton('Start', clicked = lambda: self.start())
    self.layout.addWidget(self.empty)

    
    self.window.setStyleSheet("background-image: url(tictactoe.png); background-attachment: fixed; background-repeat: no-repeat; background-position: center; background-color: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #ffc982, stop:1 #ff9982);")
    
    
    self.buttonstart.setStyleSheet("background-image: url(); border-width: 4px; border-style: solid; border-radius: 10%; border-color: black; background-color: transparent; color: black; max-width: 200%;  height: 80px; font-size: 30px;")
    self.buttonstart.setGeometry(100,100,100,100) #not working too
    
    
    self.layout.addWidget(self.buttonstart)
    self.window.setLayout(self.layout) 
    self.window.show()
    self.app.exec_()

It looks like that: The problem:
The problem

question from:https://stackoverflow.com/questions/65909615/cant-set-background-image-fixed-still

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...