首頁>技術>

簡介

qt是linux下面最通用的gui 框架,可以用來開發各種GUI程式,Python, 宇宙第一動態語言,就沒有幹不了的活。他們相結合,會碰撞出什麼樣的火花呢? 我們來試試。

Python2 生命即將結束,就不再用Python2 來做教程了,推薦大家現在立刻馬上開始學python3

開始
mkdir ~/tmp/demoqtcd ~/tmp/demoqtpipenv --threepipenv install PySide2vi main.py# 下面是程式碼內容import sysimport randomfrom PySide2.QtWidgets import (QApplication, QLabel, QPushButton, QVBoxLayout, QWidget)from PySide2.QtCore import Slot, Qtclass 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(random.choice(self.hello))if __name__ == "__main__": app = QApplication(sys.argv) widget = MyWidget() widget.resize(800, 600) widget.show() sys.exit(app.exec_()) # 程式碼輸入完了, 執行pipenv shellcd ~/tmp/demoqtpython main.py

你會看到一個GUI視窗

  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 全球公共「DNS」解析伺服器推薦。哪家強?