-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
61 lines (50 loc) · 1.79 KB
/
main.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
58
59
60
61
import sys
import numpy as np
from PyQt5.QtWidgets import QWidget, QLabel, QApplication
from PyQt5 import QtCore
class MyLabel(QLabel):
def __init__(self,*args,**kwargs):
super(MyLabel,self).__init__(*args,**kwargs)
#here we reimplement the function to respond user event
def mousePressEvent(self,e):
if e.buttons() == QtCore.Qt.LeftButton:
print(self.text()+' generated by left button clicked.')
if e.buttons() == QtCore.Qt.RightButton:
print(self.text()+' which is translated')
class MainWin(QWidget):
def __init__(self):
super().__init__()
self.initParam()
self.fReading()
self.initUI()
def initParam(self):
self.lenSentence = 25
self.fPath = "E:\Codes\PythonProjects\Learning\hackthon\something_to_read.txt"
def fReading(self):
self.data = []
with open(self.fPath,'r',encoding="ANSI") as f:
for line in f:
cells = line.strip().split(" ")
self.data.append(cells)
data = []
for row in self.data:
for c in row:
data.append(c)
self.data = data
def rearranging(self):
for y in range(3):
for x in range(self.lenSentence):
lbl = MyLabel(self.data[(x+1)*(y+1)],self)
lbl.move(50*x + 50,50*y + 10)
def initUI(self):
# print(self.data)
self.rearranging()
# lbl1 = MyLabel('how', self)
# lbl1.move(15, 10)
self.setGeometry(300, 300, 1550, 850)
self.setWindowTitle('Window')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWin()
sys.exit(app.exec_())