Python Gui PyQt5 #1

in #deutscht6 years ago (edited)

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_())

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.031
BTC 61665.59
ETH 2884.57
USDT 1.00
SBD 3.62