-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui4.py
57 lines (43 loc) · 1.65 KB
/
gui4.py
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
import sys
import json
import random
import os
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
from PyQt5.QtGui import QFont
class JsonViewer(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
self.load_json()
def init_ui(self):
self.setWindowTitle('JSON Viewer')
self.layout = QVBoxLayout()
self.label = QLabel()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
def load_json(self):
file_path = os.path.join(os.path.dirname(__file__), 'output.json') # Replace with your actual file name
try:
with open(file_path, 'r') as file:
data = json.load(file)
if isinstance(data, dict):
if data:
random_key = random.choice(list(data.keys()))
random_object = data[random_key]
# Increase the font size
font = QFont("Arial", 14) # Adjust the size as needed
self.label.setFont(font)
self.label.setText(f"Word: {random_object['mb-0 word']}\nDefinition: {random_object['definition']}\nSentence: {random_object['sentence']}")
else:
self.label.setText('The JSON file is empty.')
else:
self.label.setText('Invalid JSON format.')
except Exception as e:
self.label.setText(f'Error: {str(e)}')
def main():
app = QApplication(sys.argv)
viewer = JsonViewer()
viewer.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()