Python 3 установка pyqt

Install pyqt

PyQt is often not installed by default. The PyQt module can be used to create desktop applications with Python. In this article you’ll learn how to install the PyQt module.

Desktop applications made with PyQt are cross platform, they will work on Microsoft Windows, Apple Mac OS X and Linux computers (including Raspberry Pi).

How to install PyQt5 on Windows?

To install PyQt on Windows there are a few steps you need to take.
First use the installer from the qt-project website, from qt to install PyQt.

Next you want to install a Python version 3.3 or newer. Check the box to add all of the PyQt5 extras. It’s not necessary to compile everything from source, you can install all the required packages with the installer.

On Python >= 3.6, you can also try this command:

It should work without problems.

How to install PyQt5 on Mac OS X?

On Apple Mac OS X installation is a bit simpler. The first step to take is to install the Mac OS X binary. This installs the PyQt GUI library.

But to use it from Python, you also need Python module. This is where the tool brew comes in.
You can use brew to install pyqt (in the terminal):

How to install PyQt5 on Linux?

Python is often installed by default on Linux (in nearly all of the distributions including Ubuntu). But you want to make sure to use Python 3, because of all the features and ease of use. You can verify that you have the newest Python version with the command:

On Ubuntu Linux they sometimes include two versions of python, python3 and python . In that case use Python 3.

Once you have Python ready, the next step is to install PyQt.

This isn’t hard to do if you have some Linux experience. You can install PyQt your software package manager. Which package manager to use depends on which Linux distribution you are using.

On Ubuntu Linux / Debian Linux you can use the command:

sudo apt-get install python3-pyqt5

For CentOS 7 use the command:

yum install qt5-qtbase-devel

For RPM-based systems (Redhat-based)

PyQt GUI Programming Tutorial

Источник

PyQt5 для начинающих

Привет, Хабр! Сегодня я вас хочу научить делать интерфейс на Python 3&PyQt5.

Установка PyQt5

Для того, чтобы установить PyQt5 в Windows или MacOS, откройте Командную строку или Терминал и введите:

Для Linux, откройте Терминал и введите:

sudo apt-get update sudo apt-get upgrade sudo apt-get install python3-pyqt5

Hello, World!

А сейчас сделаем Hello World приложение. Создайте файл Python, откройте его и введите такой код:

from PyQt5.QtWidgets import * import sys class MainWindow(QMainWindow): # главное окно def __init__(self, parent=None): super().__init__(parent) self.setupUi() def setupUi(self): self.setWindowTitle("Hello, world") # заголовок окна self.move(300, 300) # положение окна self.resize(200, 200) # размер окна self.lbl = QLabel('Hello, world. ', self) self.lbl.move(30, 30) if __name__ == "__main__": app = QApplication(sys.argv) win = MainWindow() win.show() sys.exit(app.exec_())

Когда вы запустите, должна получится примерно такая картина:

Окно Hello, world на Ubuntu

Меняем шрифт надписи

А теперь поменяем шрифт надписи. Теперь код станет таким:

from PyQt5.QtWidgets import * from PyQt5.QtGui import * import sys class MainWindow(QMainWindow): # главное окно def __init__(self, parent=None): super().__init__(parent) self.setupUi() def setupUi(self): self.setWindowTitle("Hello, world") # заголовок окна self.move(300, 300) # положение окна self.resize(200, 200) # размер окна self.lbl = QLabel('Hello, world. ', self) self.lbl.move(30, 30) self.font = QFont() # создаём объект шрифта self.font.setFamily("Rubik") # название шрифта self.font.setPointSize(12) # размер шрифта self.font.setUnderline(True) # подчёркивание self.lbl.setFont(self.font) # задаём шрифт метке if __name__ == "__main__": app = QApplication(sys.argv) win = MainWindow() win.show() sys.exit(app.exec_()) 

Пример рассчитан на то, что у вас уже установлен шрифт Rubik от Google Fonts. Если нет, его всегда можно скачать отсюда.

Более продвинутая разметка с XHTML

А теперь добавим XHTML. Например, так:

from PyQt5.QtWidgets import * import sys class MainWindow(QMainWindow): # главное окно def __init__(self, parent=None): super().__init__(parent) self.setupUi() def setupUi(self): self.setWindowTitle("Hello, world") # заголовок окна self.move(300, 300) # положение окна self.resize(200, 200) # размер окна self.lbl = QLabel('Hello, world. 123', self) self.lbl.move(30, 30) if __name__ == "__main__": app = QApplication(sys.argv) win = MainWindow() win.show() sys.exit(app.exec_()) 

Те, кто хотя бы немного знают XHTML, заметят, что надпись Hello сделана курсивом, слово world — жирным, а 123 — и вычеркнуто, и жирное.

Источник

Читайте также:  Google authenticator api php
Оцените статью