简单的GUI翻译界面
界面展示
![在这里插入图片描述](https://img-blog.csdnimg.cn/f4700a7f2ab24b66a7ebac6434ed6925.png)
from PyQt5.Qt import *
import sys
import json
import requests
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("阿边的翻译软件")
self.resize(800, 600)
self.setup_ui()
self.setCursor(Qt.ForbiddenCursor)
self.drawn()
def drawn(self):
self.palette = QPalette()
self.palette.setBrush(QPalette.Background, QBrush(QPixmap("/Users/bianningtao/Desktop/professional/python/爬虫/爬虫视频/2.gif")))
self.setPalette(self.palette)
def setup_ui(self):
label = QLabel(self)
label.setText("标签")
label.move(100, 50)
label.hide()
te = QTextEdit(self)
te2 = QTextEdit(self)
te.resize(500,200)
te2.resize(500,200)
te.move(50,10)
te2.move(50,300)
te.setPlaceholderText("请输入你要翻译的内容")
te.setFontPointSize(20)
te2.setFontPointSize(20)
btn = QPushButton(self)
btn.setText("翻译")
btn.resize(100,100)
btn.move(600,200)
def translation(keys):
url = 'https://fanyi.baidu.com/sug'
data = {
'kw': keys
}
resp = requests.get(url, data).text
obj = json.loads(resp)
strs = ''
for item in obj['data']:
strs = strs + '\n' + item["v"]
te2.setText(strs)
btn.clicked.connect(lambda: translation(te.toPlainText()))
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())