Skip to content
Related Articles

Related Articles

move() method in PyQt5
  • Last Updated : 26 Mar, 2020

In order to move (changing the position) any widget like buttons or label move() method is used in PyQt5 application. By default, all the widgets are on top left corner therefore, there is a need of changing the position of the widgets.

Syntax : move( x, y )

Arguments : It takes two arguments :
1. X co-ordinate
2. Y co-ordinate

Below is the implementation of this method.




# importing the required libraries
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
  
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
  
        # set the title
        self.setWindowTitle("Move")
  
        # setting  the geometry of window
        self.setGeometry(0, 0, 400, 300)
  
        # creating a label widget
        self.widget = QLabel('Moved', self)
  
        # moving the widget
        # move(left, top)
        self.widget.move(50, 50)
  
  
        # show all the widgets
        self.show()
  
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())

Output :
pyqt-move-widget

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :