1
+ from PyQt5 .QtWidgets import QApplication , QWidget , QRadioButton , QPushButton , QListWidget , QLabel , QVBoxLayout , QHBoxLayout , QLineEdit
2
+ with open ('dictionary.txt' ) as dic :
3
+ dic = dic .read ().split ('\n ' )
4
+
5
+ class ADD (QWidget ):
6
+ def __init__ (self ):
7
+ super ().__init__ ()
8
+
9
+ self .hBtnEditLay = QHBoxLayout ()
10
+ self .vEditLay = QVBoxLayout ()
11
+ self .vMainLay = QVBoxLayout ()
12
+
13
+ self .engEdit = QLineEdit ()
14
+ self .engEdit .setPlaceholderText ("Eng..." )
15
+
16
+ self .uzEdit = QLineEdit ()
17
+ self .uzEdit .setPlaceholderText ("Uzb..." )
18
+
19
+ self .okBtn = QPushButton ("OK" )
20
+ self .okBtn .clicked .connect (self .ok )
21
+
22
+ self .natijaLbl = QLabel ("" )
23
+
24
+ self .menuBtn = QPushButton ("MENU" )
25
+ self .menuBtn .clicked .connect (self .menu )
26
+
27
+ self .vEditLay .addWidget (self .engEdit )
28
+ self .vEditLay .addWidget (self .uzEdit )
29
+
30
+ self .hBtnEditLay .addLayout (self .vEditLay )
31
+ self .hBtnEditLay .addWidget (self .okBtn )
32
+
33
+ self .vMainLay .addLayout (self .hBtnEditLay )
34
+ self .vMainLay .addWidget (self .natijaLbl )
35
+ self .vMainLay .addWidget (self .menuBtn )
36
+
37
+ self .setLayout (self .vMainLay )
38
+
39
+ def ok (self ):
40
+
41
+
42
+
43
+ if self .engEdit .text ()== '' or self .uzEdit .text ()== '' :
44
+ self .natijaLbl .setText ('No\' to\' g\' ri malumot kiritdingiz !' )
45
+ self .natijaLbl .adjustSize ()
46
+ else :
47
+ co = 0
48
+ for i in dic :
49
+ i = i .split ()
50
+ if self .engEdit .text ()== i [0 ] or self .uzEdit .text ()== i [1 ]:
51
+ self .natijaLbl .setText ("Bu so'z allaqachon mavjud !" )
52
+ self .natijaLbl .adjustSize ()
53
+ co = 1
54
+ if co == 0 :
55
+ dic .append (f"{ self .engEdit .text ()} { ' ' * (20 - len (self .engEdit .text ()))} { self .uzEdit .text ()} " )
56
+ self .natijaLbl .setText ("So'z qo'shildi !" )
57
+
58
+ # paused
59
+ self .engEdit .clear ()
60
+ self .uzEdit .clear ()
61
+
62
+ def menu (self ):
63
+ self .engEdit .clear ()
64
+ self .uzEdit .clear ()
65
+ self .natijaLbl .setText ("" )
66
+ self .close ()
67
+
68
+ class SEARCH (QWidget ):
69
+ def __init__ (self ):
70
+ super ().__init__ ()
71
+
72
+ self .hRadioLay = QHBoxLayout ()
73
+ self .hEditBtnLay = QHBoxLayout ()
74
+ self .vMainLay = QVBoxLayout ()
75
+
76
+ self .EngRadio = QRadioButton ("Englsih" )
77
+ self .EngRadio .setChecked (True )
78
+ self .UzRadio = QRadioButton ('Uzbek' )
79
+
80
+ self .Edit = QLineEdit ()
81
+
82
+ self .searchBtn = QPushButton ("search" )
83
+ self .searchBtn .clicked .connect (self .search )
84
+
85
+ self .lbl = QLabel ("" )
86
+
87
+ self .menuBtn = QPushButton ("MENU" )
88
+ self .menuBtn .clicked .connect (self .menu )
89
+
90
+ self .hRadioLay .addWidget (self .EngRadio )
91
+ self .hRadioLay .addWidget (self .UzRadio )
92
+
93
+ self .hEditBtnLay .addWidget (self .Edit )
94
+ self .hEditBtnLay .addWidget (self .searchBtn )
95
+
96
+ self .vMainLay .addLayout (self .hRadioLay )
97
+ self .vMainLay .addLayout (self .hEditBtnLay )
98
+ self .vMainLay .addWidget (self .lbl )
99
+ self .vMainLay .addWidget (self .menuBtn )
100
+
101
+ self .setLayout (self .vMainLay )
102
+
103
+ def search (self ):
104
+ global dic
105
+ co = True
106
+ if self .EngRadio .isChecked ():
107
+ for i in dic :
108
+ i = i .split ()
109
+ if i [0 ]== self .Edit .text ():
110
+ self .lbl .setText (i [1 ])
111
+ self .lbl .adjustSize ()
112
+ co = False
113
+ elif self .UzRadio .isChecked ():
114
+ for i in dic :
115
+ i = i .split ()
116
+ if i [1 ]== self .Edit .text ():
117
+ self .lbl .setText (i [0 ])
118
+ self .lbl .adjustSize ()
119
+ co = False
120
+ if co :
121
+ self .lbl .setText ("Bunday so'z topilmadi !" )
122
+ self .lbl .adjustSize ()
123
+
124
+ def menu (self ):
125
+ self .Edit .clear ()
126
+ self .lbl .clear ()
127
+ self .close ()
128
+
129
+ class LIST (QWidget ):
130
+ def __init__ (self ):
131
+ super ().__init__ ()
132
+
133
+ self .hLblLay = QHBoxLayout ()
134
+ self .hListWidgLay = QHBoxLayout ()
135
+ self .vMainLay = QVBoxLayout ()
136
+
137
+ self .engLbl = QLabel ("English" )
138
+ self .uzLbl = QLabel ("Uzbek" )
139
+
140
+ self .engListWdg = QListWidget ()
141
+ self .uzListWdg = QListWidget ()
142
+ self .menuBtn = QPushButton ("MENU" )
143
+ self .menuBtn .clicked .connect (self .menu )
144
+
145
+ global dic
146
+
147
+ pic = dic .copy ()
148
+ for i in range (len (pic )):
149
+ pic [i ]= pic [i ].split ()
150
+ self .engListWdg .addItem (f"{ i + 1 } -{ pic [i ][0 ]} " )
151
+ self .uzListWdg .addItem (f"{ i + 1 } -{ pic [i ][1 ]} " )
152
+
153
+ self .hLblLay .addWidget (self .engLbl )
154
+ self .hLblLay .addWidget (self .uzLbl )
155
+
156
+ self .hListWidgLay .addWidget (self .engListWdg )
157
+ self .hListWidgLay .addWidget (self .uzListWdg )
158
+
159
+ self .vMainLay .addLayout (self .hLblLay )
160
+ self .vMainLay .addLayout (self .hListWidgLay )
161
+ self .vMainLay .addWidget (self .menuBtn )
162
+
163
+ self .setLayout (self .vMainLay )
164
+
165
+ def menu (self ):
166
+ self .engListWdg .clear ()
167
+ self .uzListWdg .clear ()
168
+ self .close ()
169
+
170
+ class MainWindow (QWidget ):
171
+ def __init__ (self ) -> None :
172
+ super ().__init__ ()
173
+
174
+ self .addWindow = ADD ()
175
+ self .searchWindow = SEARCH ()
176
+
177
+ self .vBtnLay = QVBoxLayout ()
178
+ self .hMainLay = QHBoxLayout ()
179
+
180
+ self .addBtn = QPushButton ("ADD" )
181
+ self .addBtn .clicked .connect (lambda : self .addWindow .show ())
182
+
183
+ self .searchBtn = QPushButton ("SEARCH" )
184
+ self .searchBtn .clicked .connect (self .searchWindow .show )
185
+
186
+ self .listBtn = QPushButton ("LIST" )
187
+ self .listBtn .clicked .connect (self .show_list )
188
+
189
+ self .exitBtn = QPushButton ("EXIT" )
190
+ self .exitBtn .clicked .connect (self .exit )
191
+
192
+ self .vBtnLay .addWidget (self .addBtn )
193
+ self .vBtnLay .addWidget (self .searchBtn )
194
+ self .vBtnLay .addWidget (self .listBtn )
195
+ self .vBtnLay .addWidget (self .exitBtn )
196
+
197
+ self .hMainLay .addStretch ()
198
+ self .hMainLay .addLayout (self .vBtnLay )
199
+ self .hMainLay .addStretch ()
200
+ self .setLayout (self .hMainLay )
201
+
202
+ def show_list (self ):
203
+ self . listWindow = LIST ()
204
+ self . listWindow .show ()
205
+
206
+ def exit (self ):
207
+ global dic
208
+
209
+ with open ("dictionary.txt" ,"w" ) as fil :
210
+ for i in range (len (dic )):
211
+ if i != len (dic )- 1 :
212
+ fil .write (f"{ dic [i ]} \n " )
213
+ else :
214
+ fil .write (f"{ dic [i ]} " )
215
+ self .close ()
216
+
217
+ app = QApplication ([])
218
+ win = MainWindow ()
219
+ win .show ()
220
+ app .exec_ ()
0 commit comments