Python GUI with PyQT5 - Insert Button

For the newbies, begin with section 1 - or directly go to section 2

Section 1

Before you go any further, make sure you have Python and that the expected version is available from your command line. You can check this by running:

python --version

You should get some output like Python 3.7.2.

python gui button 1

 

 

 

 

 

Install PyQT5 using
pip install pyqt5
Command
 

python gui

 

SECTION 2

Write your code in Notepad, and then rename it to yourcode.py

python GUI

 

 

 

 

 

 

 

To run, Rightclick on yourcode.py, then select “Edit with IDLE 3.7”

 

python CAA

 

 

 

 

 

 

THE CODE

from PyQt5.QtWidgets import QApplication,QWidget,QPushButton
from PyQt5.QtCore import pyqtSlot
import sys
class App(
QWidget):
      
def __init__(self):
               super().__
init__()
              
self.title='Adding Buttons to the Form'
              
self.left=200
              
self.top=200
              
self.width=500
              
self.height=500
              
self.initUI()
      
def initUI(self):
              
self.setWindowTitle(self.title)
              
self.setGeometry(self.left,self.top,self.width,self.height)
               button=
QPushButton('Click Here',self)
              
button.setToolTip('Help Text')
              
button.move(200,200)
              
self.show()
if __name__=='__main__':
       app=
QApplication(sys.argv)
       ex=App()

In IDLE, it looks like


python caa

 

 

 

 

 

 

 

 

 

Now Run the module (press F5), you should get the out put like this

python gui