Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add a button pyqt5

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot

class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 button - pythonspot.com'
        self.left = 10
        self.top = 10
        self.width = 320
        self.height = 200
        self.initUI()
    
    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        
        button = QPushButton('PyQt5 button', self)
        button.setToolTip('This is an example button')
        button.move(100,70)
        button.clicked.connect(self.on_click)
        
        self.show()

    @pyqtSlot()
    def on_click(self):
        print('PyQt5 button click')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())
Comment

pyqt5 button example

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")

        button = QPushButton("Press Me!")
        button.setCheckable(True)
        button.clicked.connect(self.the_button_was_clicked)

        # Set the central widget of the Window.
        self.setCentralWidget(button)

    def the_button_was_clicked(self):
        print("Clicked!")


app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()
Comment

pyqt5 buttons

    b1 = QtWidgets.QPushButton(win)
    b1.setText("click me")
    #b1.move(100,100) to move the button
Comment

PREVIOUS NEXT
Code Example
Python :: python super init 
Python :: converting jupyter notebook files to python 
Python :: how to check which submit button is clicked in flask wtf 
Python :: pyspark check all columns for null values 
Python :: linear congruential generator in python 
Python :: plt multiple figures to show 
Python :: how to multiply two arrays in python 
Python :: how to read text frome another file pythion 
Python :: how to input a string in streamlit 
Python :: remove all whitespace from string python 
Python :: convert string to list python 
Python :: numpy matrix 
Python :: python file handling 
Python :: ParserError: Error tokenizing data. C error: Expected 1 fields in line 6, saw 3 
Python :: get column number in dataframe pandas 
Python :: pygame music player 
Python :: python remove last element from list 
Python :: python set intersection 
Python :: python reduce() 
Python :: create bigram in python 
Python :: dataframe groupby multiple columns 
Python :: check if string contains alphabets python 
Python :: remove spaces from string python 
Python :: string hex to decimal python 
Python :: renaming column in dataframe pandas 
Python :: extend a class python 
Python :: create alinked list inb pyhton 
Python :: python pandas replace not working 
Python :: how to detect if the space button is pressed in pygame 
Python :: python open file relative to script location 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =