4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Python Gui PyQt5 #2 Buttons

Bildschirmfoto vom 2018-03-30 21-52-21.png


import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QToolTip
from PyQt5.QtGui import  QIcon ,QFont
from PyQt5 import QtCore
a = []
app = QApplication(a)
w = QWidget()
w.setGeometry(50,50,700,500)
w.setWindowTitle("Gui1")
w.setWindowIcon(QIcon('F.png'))

#  *** Neu ***

button = QPushButton("Push to Close!",w) # Setzt ein Button auf den Fenster(w) mit dem Text "Push to Close!".
button.move(300,200) # Setzt den Button auf (300,200)
button.clicked.connect(QtCore.QCoreApplication.instance().quit) # Wenn der Button gedrückt wird, wird das Programm beendet.

# *** *** ***

w.show()
sys.exit(app.exec_())

Das meiste müsste aus dem letzten Post bekannt sein.
Neu ist der Button.
Mit QPushButton() wird er erstellt.
Er kann bewekt (.move()) werden.
Interagieren kann man mit .clicked.connect().
In den klammern steht die Aktion die beim Drücken ausgeführt wird.
In diesem Fall wird das Programm beendet.


Fenster:
Bildschirmfoto vom 2018-03-31 02-28-50.png

5 upvotes $0.00

Replies (0)

Conversation

No replies yet

Replies will appear here as people join the conversation.

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: