from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
requests
import
sys
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle("Python ")
self
.setGeometry(
100
,
100
,
400
,
500
)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
push
=
QPushButton("Press",
self
)
push.setGeometry(
125
,
100
,
150
,
40
)
self
.label
=
QLabel("Press button to see your IP",
self
)
self
.label.setGeometry(
100
,
200
,
200
,
40
)
self
.label.setAlignment(Qt.AlignCenter)
self
.label.setStyleSheet("border :
3px
solid black;")
push.clicked.connect(
self
.get_ip)
def
get_ip(
self
):
r
=
requests.get("http:
/
/
httpbin.org
/
ip")
ip
=
r.json()[
'origin'
]
parsed
=
ip.split(", ")[
0
]
self
.label.setText(parsed)
self
.label.setFont(QFont(
'Times'
,
12
))
App
=
QApplication(sys.argv)
window
=
Window()
window.show()
sys.exit(App.
exec
())