首頁>技術>

PySide2是Qt官方出品,18年正式開始釋出。PyQt是以前Nokia推出的。

這裡介紹PySide2快速編寫跨平臺GUI Demo。

安裝

目前最新的是5.14版本

pip install pyside2

其安裝兩個包:

pyside2: contains all the PySide2 module for all the Qt libraries. Also depends on the shiboken2 module.

shiboken2: contains the shiboken2 module with helper functions for PySide2.

程式碼

# -*- coding: utf-8 -*-

import sys

import random

from PySide2.QtWidgets import (QApplication, QLabel, QPushButton,

QVBoxLayout, QWidget)

from PySide2.QtCore import Slot, Qt

class MyWidget(QWidget):

def __init__(self):

QWidget.__init__(self)

self.hello = ["Hallo Welt", "你好,世界", "Hei maailma",

"Hola Mundo", "Привет мир"]

self.button = QPushButton("Click me!")

self.text = QLabel("Hello World")

self.text.setAlignment(Qt.AlignCenter)

self.layout = QVBoxLayout()

self.layout.addWidget(self.text)

self.layout.addWidget(self.button)

self.setLayout(self.layout)

# Connecting the signal

self.button.clicked.connect(self.magic)

@Slot()

def magic(self):

self.text.setText('\\n'.join(self.hello))

if __name__ == "__main__":

app = QApplication(sys.argv)

widget = MyWidget()

widget.resize(800, 600)

widget.show()

sys.exit(app.exec_())

364

Qt

Python

最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 當 Flutter 遇見 Web,會有怎樣的祕密?