4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Python Gui PyQt5 #1

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


PyQt5 ist ein GUI-Toolkit
Es bringt das Anwendungsframework Qt (c++) und Python zusammen.
PyQt5 unterschützt Windows, OS X, Linux, iOS und Android.


Instalation

pip install PyQt5


Erstes Programm

Zuerst muss sys und PyQt5 importiert werden.

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import  QIcon


Danach wird eine neue Applikation und ein neues Fenster erstellt und ausgegeben.

a = []
app = QApplication(a)
w = QWidget()
w.show()


Mit sys.exit(app.exec_()) wird das Programm beendet,
wenn das Fenster geschlossen wird.
Das Fenster sieht wie folgt aus.
Bildschirmfoto vom 2018-03-30 23-08-06.png.png
Das Fenster ist leer und hat auch kein Icon.

Im folgenden wird die Größe und die Position, sowie der Titel und das Icon Festgelegt.

w.setGeometry(50,50,700,500)
w.setWindowTitle("Gui1")
w.setWindowIcon(QIcon('F.png'))

Als erstes wird das Fenster auf Position 50 : 50 verschoben.
700 ist die Breite und 500 ist die höhe.
Der Titel wird auf Gui1 gesetzt.
Das Bild muss im gleichen Ordner sein, dann kann es so benutzt werden.
Das Fenster:
Bildschirmfoto vom 2018-03-30 23-35-07.png.png


Der komplette Code:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import  QIcon

a = []
app = QApplication(a)
w = QWidget()

w.setGeometry(50,50,700,500)
w.setWindowTitle("Gui1")
w.setWindowIcon(QIcon('F.png'))


w.show()
sys.exit(app.exec_())
8 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: