我是靠谱客的博主 清秀镜子,这篇文章主要介绍Pyqt - Button,现在分享给大家,希望可以做个参考。

 

Listening 繁华的寂静!


来小例子:

点击AA,BB按钮后会弹出文件选择框,点击Show按钮后会弹出文本输入框,输入后点击确认,然后你输入的东东显示在右侧的显示框框。

Show me the code:  -- ui框架的力量啊:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys import os from PyQt5.QtWidgets import ( QWidget, QMainWindow, QPushButton, QLineEdit, QInputDialog, QApplication, QFrame, QColorDialog, QVBoxLayout, QSizePolicy, QLabel, QFontDialog, QTextEdit, QAction, QFileDialog ) from PyQt5.QtGui import QColor from PyQt5.QtGui import QIcon import compareData class MyForm(QMainWindow): def __init__(self): super(MyForm, self).__init__() self._init_ui_1() self.file_a='' def _init_ui_1(self): self.btn = QPushButton('AA', self) self.btn.move(20, 20) self.btn2 = QPushButton('BB', self) self.btn2.move(20, 60) self.btn3 = QPushButton('Show', self) self.btn3.move(20, 120) self.btn3.clicked.connect(self.showDialog_1) self.btn.clicked.connect(self.a_file_sel) self.btn2.clicked.connect(self.b_file_sel) self.le = QLineEdit(self) self.le.move(130, 120) self.setGeometry(800, 300, 500, 300) self.setWindowTitle('Input dialog') self.show() def showDialog_1(self): text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter your name:') if ok: self.le.setText(str(text)) else: self.le.setText(str(ok)) def a_file_sel(self): # Please do not: self.QFileDialog.getOpenFileName,because this will cause break down fileName, fileType = QFileDialog.getOpenFileName(self, "data", os.getcwd(), "All Files(*);;json Files(*.json)") self.file_a = fileName print(self.file_a) print(fileType) def b_file_sel(self): fileName, fileType = QFileDialog.getOpenFileName(self, "data", os.getcwd(), "All Files(*);;json Files(*.json)") print(fileName) print(fileType) if __name__ == '__main__': app = QApplication(sys.argv) form = MyForm() sys.exit(app.exec_()) pass

 

Ref:

https://blog.csdn.net/freeking101/article/details/96477744

最后

以上就是清秀镜子最近收集整理的关于Pyqt - Button的全部内容,更多相关Pyqt内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(87)

评论列表共有 0 条评论

立即
投稿
返回
顶部