-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
executable file
·35 lines (24 loc) · 921 Bytes
/
convert.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
#!/usr/bin/python3
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout, QLineEdit, QPushButton
def convert():
"""Takes miles entered, converts them to km, and displays the result"""
miles = float(entryMiles.text())
entryKm.setText(str(miles * 1.60934))
app = QApplication([])
rootWindow = QWidget()
rootWindow.setWindowTitle("Miles to kilometers")
rootWindow.resize(500, 200)
gridLayout = QGridLayout(rootWindow)
labelMiles = QLabel('Distance in miles:')
gridLayout.addWidget(labelMiles, 0, 0)
labelKm = QLabel('Distance in kilometers:')
gridLayout.addWidget(labelKm, 2, 0)
entryMiles = QLineEdit()
gridLayout.addWidget(entryMiles, 0, 1)
entryKm = QLineEdit()
gridLayout.addWidget(entryKm, 2, 1)
convertButton = QPushButton('Convert')
gridLayout.addWidget(convertButton, 1, 1)
convertButton.clicked.connect(convert)
rootWindow.show()
app.exec_()