parent
4d78f7f0dd
commit
60506e0d4a
@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
with open('demo.json','r',encoding='utf-8') as f:
|
with open('18503.json','r',encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for i,j in enumerate(data.items()):
|
|
||||||
print(i,j[-1])
|
for i,j in data.items():
|
||||||
|
print(j['answer'])
|
||||||
|
print('-'*50)
|
@ -0,0 +1,48 @@
|
|||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QTextEdit
|
||||||
|
from PyQt5.QtCore import QTimer
|
||||||
|
|
||||||
|
class TypewriterEffectApp(QWidget):
|
||||||
|
def __init__(self, filepath):
|
||||||
|
super().__init__()
|
||||||
|
self.filepath = filepath
|
||||||
|
self.initUI()
|
||||||
|
self.startTyping()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
# 设置窗口布局和控件
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
self.textEdit = QTextEdit(self)
|
||||||
|
self.textEdit.setReadOnly(True)
|
||||||
|
layout.addWidget(self.textEdit)
|
||||||
|
|
||||||
|
# 设置窗口
|
||||||
|
self.setWindowTitle("Typewriter Effect")
|
||||||
|
self.setGeometry(300, 300, 600, 400)
|
||||||
|
|
||||||
|
def startTyping(self):
|
||||||
|
# 读取文件内容
|
||||||
|
with open(self.filepath, 'r') as file:
|
||||||
|
self.content = file.read()
|
||||||
|
|
||||||
|
# 设置定时器逐字显示文本
|
||||||
|
self.index = 0
|
||||||
|
self.timer = QTimer(self)
|
||||||
|
self.timer.timeout.connect(self.displayNextCharacter)
|
||||||
|
self.timer.start(100) # 设置间隔(毫秒)
|
||||||
|
|
||||||
|
def displayNextCharacter(self):
|
||||||
|
if self.index < len(self.content):
|
||||||
|
self.textEdit.insertPlainText(self.content[self.index])
|
||||||
|
self.index += 1
|
||||||
|
else:
|
||||||
|
self.timer.stop()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
ex = TypewriterEffectApp('path_to_text_file.txt') # 替换为您的文件路径
|
||||||
|
ex.show()
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -0,0 +1,5 @@
|
|||||||
|
为了在您的代码中加入光标闪烁效果,我们可以使用一个额外的定时器来控制一个虚拟光标(例如一个竖线符号 '|')的显示和隐藏。这样,您的应用程序在显示文本的同时,也会模拟一个正在输入的效果。
|
||||||
|
|
||||||
|
以下是修改后的代码:
|
||||||
|
|
||||||
|
修改后的代码
|
Loading…
Reference in new issue