Answer the question
In order to leave comments, you need to log in
Pyqt5 The program that should show the weather?
The program on pyqt5 made the design in qt designer, converted from ui to .py the program starts but does not display how many degrees. I ALREADY TRIED: replace from city to place, but it didn’t work, it seems there are no literal errors, what to do, here is the code.
import sys, pyowm
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon
from weather import Ui_MainWindow
#create app
app = QtWidgets.QApplication(sys.argv)
# init
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
def get_weather_city():
owm = pyowm.OWM('31dd6799e9426588099cc987780b7eb6')
city = ui.lineEdit.text()
observation = owm.weather_at_place(city)
w = observation.get_weather()
temperature = w.get_temperature ('celsius')['temp']
ui.label.setText( f'Температура: {temperature}')
ui.pushButton.clicked.connect(get_weather_city)
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
from PyQt5 import QtWidgets, uic
import sys
from pyowm import OWM
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui, self).__init__()
uic.loadUi('weather.ui', self)
city = "Ленинск-Кузнецкий"
owm = OWM('31dd6799e9426588099cc987780b7eb6')
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
temperature = w.temperature('celsius')['temp']
self.label.setText( f'В городе: {city} сейчас температура: {temperature}')
self.show()
app = QtWidgets.QApplication(sys.argv)
window = Ui()
app.exec_()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question