大理缘:朋友爱与创业奋斗记
Advertisement
清晨的第一縷過窗簾的隙,輕輕地拂過我的臉頰。手機界面上,鐵男發來的位置信息在微中顯得格外清晰。我不深吸一口氣,將其轉發給了桃子,心中卻沒有太多的波瀾。我深知,無論友還是,都如同夜幕中的星辰,即使璀璨奪目,也終將歸于沉寂。
我不冷漠,只是深知,如水,波濤洶涌,起伏不定,又怎能輕易置其間, PyQt5 是一個功能強大的平臺應用程序開發工,它允許開發者使用 Python 語言創建有 GUI 的桌面應用程序,并且能夠運行在 Windows、Mac、Linux 等不同的作系統上。以下是一些關于如何使用 PyQt5 開發桌面應用程序的基本步驟:
### 安裝 PyQt5
首先,你需要安裝 PyQt5。可以通過以下命令在你的系統上安裝:
```bash
pip install PyQt5
```
### 創建主窗口
PyQt5 的基礎是 `QMainWindow` 或 `QWidget`。以下是如何創建一個簡單的基于 `QMainWindow` 的窗口的示例:
```python
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt5 窗口示例')
self.setGeometry(100, 100, 400, 300)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
```
### 添加部件
在窗口中,你可以添加各種部件,如按鈕、文本框等。以下是如何在窗口中添加一個按鈕的示例:
```python
from PyQt5.QtWidgets import QPushButton
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt5 窗口示例')
self.setGeometry(100, 100, 400, 300)
self.button = QPushButton('點擊我', self)
self.button.setGeometry(100, 100, 200, 100)
self.button.clicked.connect(self.on_button_clicked)
def on_button_clicked(self):
print('按鈕被點擊了')
```
### 事件理
PyQt5 中的事件理是通過信號和槽來實現的。以下是如何將按鈕的點擊事件與一個方法關聯的示例:
```python
from PyQt5.QtCore import pyqtSlot
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt5 窗口示例')
self.setGeometry(100, 100, 400, 300)
self.button = QPushButton('點擊我', self)
self.button.setGeometry(100, 100, 200, 100)
self.button.clicked.connect(self.on_button_clicked)
@pyqtSlot()
def on_button_clicked(self):
print('按鈕被點擊了')
```
### 化窗口
PyQt5 提供了富的樣式和主題,你可以通過 CSS 或樣式表來化你的應用程序。以下是如何應用一個簡單的樣式表的示例:
```python
from PyQt5.QtWidgets import QApplication, QLabel
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt5 窗口示例')
self.setGeometry(100, 100, 400, 300)
self.label = QLabel('歡迎使用 PyQt5!', self)
self.label.setStyleSheet('color: white; background-color: black;')
self.label.setGeometry(50, 50, 300, 100)
```
### 實現多窗口
如果需要創建多個窗口,可以使用 `QStackedWidget` 或 `QTabWidget` 等控件來管理窗口。以下是如何使用 `QStackedWidget` 創建多個窗口的示例:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QStackedWidget
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt5 多窗口示例')
self.setGeometry(100, 100, 400, 300)
self.stacked_widget = QStackedWidget(self)
self.setCentralWidget(self.stacked_widget)
self.window1 = QWidget()
self.window1_button = QPushButton('打開窗口2', self.window1)
self.window1_button.clicked.connect(self.show_window2)
self.window1_layout = QVBoxLayout()
self.window1_layout.addWidget(self.window1_button)
self.window1.setLayout(self.window1_layout)
self.window2 = QWidget()
self.window2_button = QPushButton('打開窗口1', self.window2)
self.window2_button.clicked.connect(self.show_window1)
self.window2_layout = QVBoxLayout()
self.window2_layout.addWidget(self.window2_button)
self.window2.setLayout(self.window2_layout)
self.stacked_widget.addWidget(self.window1)
self.stacked_widget.addWidget(self.window2)
def show_window1(self):
self.stacked_widget.setCurrentWidget(self.window1)
def show_window2(self):
self.stacked_widget.setCurrentWidget(self.window2)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
```
通過這些步驟,你可以開發出各種功能的桌面應用程序。PyQt5 的強大之在于其富的控件和事件理機制,能夠讓你輕松地創建出觀且功能齊全的應用程序。
Advertisement
護犢師尊
耗盡受命成為最強競技大帝,卻在出關時遭到老祖舉全宗之力鎮壓。只因世人覺得我是只會惹是生非的禍害。 就在我即將被趕出宗門時,一道聲音震響整個禁忌宗。在場的強者瞬間感到一股大帝威壓,來者正是三長老鷹玄。 自從我拜入他門下後,就一直閉關,已經有十年沒見過他。 “乖徒兒,今日有為師在,沒人能趕你出宗!” 鷹玄的話音剛落下,腦海中就傳來系統的提示:“叮!獲得護犢之家1萬。” 我剛穿越時就覺醒了護犢子系統,只要有人替我出頭就能獲得護犢子積分,可以在系統商城裏兌換丹藥、神體等修煉資源。可十年來師父一直閉關,我各種作死,企圖讓這個不怎麼靠譜的師尊出關為自己出頭。
8 1826逆天斷絕
为了能泡上90歲的老baby,爺爺竟給你找了個懷胎8月的未婚妻,甚至還揚言不當接盤俠,就與你斷絕關係。正好這時你覺醒了最強致富系統,只要斷絕關係,一天就能獎勵10個億。就在你思考如何做出決定時,挺著大肚子的柳如煙對你嘲諷道: “肚子裏的孩子是我男神的,這個孩子我不僅不會打掉,我還會生下來。” 而你爺爺這時候也附和道:“等劉小姐孩子生下來,就讓孩子跟著你姓。你把孩子當成你親生的就行了,沒什麼大不了的。” 聞言你氣憤不已,然而還未等你開口,柳如煙十分不屑地說道:“孩子跟著他姓?怎麼可能!我男神的孩子怎麼配跟著他姓,他得跟著我男神的姓。訂婚以後他就改姓秦了。” 這時,一旁的七大姑八大姨都附和著說道:“這可是百年難得一遇的機會,小凡你可要抓住啊!”
8 24380登頂劍尊
你明明是無敵於九天十地的無上劍神,卻故意隱藏修為,在宗門裏當個瞎子雜役。每天不是在院子裏喂狗掃地,就是在菜地裏當人形推土機。師兄弟們每天嘲諷你是個沒用的廢物,但是他們不知道的是,他們眼中的廢物瞎子乃是宗門封號榜中第一的最強劍神。 只因你獲得最強簽到系統,簽到百年,一身修為已入巔峰之境。這晚你看見一個斷臂少年半夜揮刀,想起了曾經的自己。看著少年堅毅的眼神,突然起了收徒之心。在少年面前揮了一刀後,與之定下十五天之約。 轉眼間,半個月時間悄然而至。
8 3118窮就富有
沒有什麼就會擁有什麼,是一種怎樣的體驗? 你踏入社會多年,但沒賺多少錢,家境也不好,跟女友也到了談婚論嫁的地步,所以生活壓力很大。就在這時,你腦海提示音響起: 系統綁定你,沒有什麼就會擁有什麼,系統一小時後開啟。 你很驚喜,竟然有了系統,並且沒有什麼就會擁有什麼,那就太厲害了。 “系統,我沒有太多東西了,都能獲得嗎?” “可以獲得,需要完成一些任務,但系統開啟後會給予大禮包。”
8 2806不忘勇士
他喵的,我明明出生在豪門,卻天天食不果腹。我一個首富之子,竟然成了一個舔狗,天天跪舔我的至親家人。舔到最後,不僅沒能使他們停止對我的虐待,甚至還被綠茶婊林佳宇設計車禍,將我撞成了植物人。
8 3225正統劍神
為了證明一件便可破萬法,我每天都不吃不喝,在宗門內揮劍練習,直到這天,宗門發生了毀天滅地的大戰。我無意間進入了一道裂縫之中,來到了一個未知世界。這個世界充滿了各種兇險,還有無數強者。 終於在萬年後的今日,我經歷了無數次的生死廝殺及苦修後,以手中之劍展開了一道虛空裂縫,回到了青峰山之巔。虛空中,我低聲喃喃道:“我回來了,大乘中期。”
8 2254