Open In App

move() method in PyQt5

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads