Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I've created window with button named "First", the window shows me next button named "Second" after clicking on the button "First", but button "Second" isn't moved by:
self.b2.move(50,50)
Whats the problem?
import sys
from PyQt5 import QtWidgets
class Window(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.init_UI()
def init_UI(self):
self.Centr= QtWidgets.QWidget()
self.setCentralWidget(self.Centr)
self.window = QtWidgets.QStackedWidget(self.Centr)
self.b1 = self.addButton()
self.window.addWidget(self.b1)
self.b2 = self.addButton_2()
self.b2.move(50,50)
self.window.addWidget(self.b2)
self.b1.clicked.connect(self.b1_clk)
self.currentStack(0)
self.show()
def addButton(self):
b1 = QtWidgets.QPushButton("First")
return b1
def addButton_2(self):
b2 = QtWidgets.QPushButton("Second")
return b2
def b1_clk(self):
self.currentStack(1)
def currentStack(self, index):
self.window.setCurrentIndex(index)
app = QtWidgets.QApplication(sys.argv)
w = Window()
sys.exit(app.exec_())
Sorry for my English.
And thank you for your attention!
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.