-
Notifications
You must be signed in to change notification settings - Fork 5
/
GUI_Calculator.py
39 lines (32 loc) · 1.14 KB
/
GUI_Calculator.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
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
if __name__ == '__main__':
class mainform(QWidget):
def __init__(self):
super().__init__()
self.getgui()
def getgui(self):
self.resize(300,100)
self.move(300,300)
self.setWindowTitle('calc')
self.textbox = QLineEdit()
self.textbox.setPlaceholderText('masukkan operasi hitung yang akan dijalankan..')
self.button = QPushButton('hitung')
self.button.clicked.connect(self.eval)
self.hasil = QLineEdit()
self.hasil.setReadOnly(True)
vbox = QVBoxLayout()
vbox.addWidget(self.textbox)
vbox.addWidget(self.hasil)
vbox.addWidget(self.button)
self.setLayout(vbox)
def eval(self):
angka = self.textbox.text()
result = str(eval(angka))
self.hasil.setText(result)
app = QApplication(sys.argv)
form = mainform()
form.show()
app.exec_()