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

PREVIOUS NEXT
Code Example
Python :: pandas categorical to numeric 
Python :: python obfuscator 
Python :: python find equal rows of two numpy arrays 
Python :: pandas dataframe sort by column name first 10 values 
Python :: python 3 custom sort with compare 
Python :: simple graph in matplotlib categorical variables 
Python :: pandas dict from row 
Python :: button in python 
Python :: random.choice 
Python :: ValueError: Found array with dim 3. Estimator expected <= 2. 
Python :: count different values in list python 
Python :: python array get index 
Python :: ping from python 
Python :: how to redirect to previous page in django 
Python :: pandas groupby mean round 
Python :: sort an array python 
Python :: what is self in python 
Python :: How are iloc and loc different? 
Python :: with suppress python 
Python :: jinja conditional syntax 
Python :: python start with 
Python :: python count values in list 
Python :: who created python 
Python :: python get value from dictionary 
Python :: matplotlib orange line 
Python :: python read scv 
Python :: how can i plot graph from 2 dataframes in same window python 
Python :: python invert an array 
Python :: start project django 
Python :: entered_text_1 = textbox_1.get(1.0, tk.END+"-1c") 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =