Solution 1: Weather Application Using Requests and OpenWeatherMap API Code: import requests # Function to fetch weather data from OpenWeatherMap API def get_weather(city_name, api_key): base_url = f"https://api.
weather.pyShow/Hide Congratulations! Your script looks great, and you’ve put a good chunk of time into building it. Maybe it’s time to go out for a walk? No, looks like it’s still raining outside. That gives you time to improve the appearance and style of your app’s output....
result=data['weatherinfo']#获取字典 self.text2.delete(0,END)#擦除text2数据 #将爬虫所得数据写入 self.text2.insert(0,result['weather'])#将爬虫所得数据写入text2 self.text3.delete(0,END)self.text3.insert(0,result['temp1'])self.text4.delete(0,END)self.text4.insert(0,result['temp2']...
Get up-to-date weather direct to your desktop, including meterological data and week-ahead predictions. The OpenWeatherMap API Requests to the API can take a few moments to complete. If we perform these in the main application loop this will cause our app to hang while waiting for data....
cityName = self.ui.weatherComboBox.currentText() # 获取天气部分省略 # 在文本框显示查询结果 self.ui.resultText.setText(result) def clearResult(self): print('* clearResult ') self.ui.resultText.clear() if __name__=="__main__": app = QApplication(sys.argv) win = MainWindow() ...
# 1、清空按钮与对应函数连接clearBtn.clicked.connect(widget.clearResult)# 2、查询按钮与对应函数连接queryBtn.clicked.connect(widget.queryWeather) 4、调用主窗口类 importsysfromPyQt5.QtWidgetsimportQApplication , QMainWindowfromWeatherWinimportUi_widgetimportrequestsimportjsonclassMainWindow(QMainWindow):def__...
(Dialog.getWeather)# type: ignoreQtCore.QMetaObject.connectSlotsByName(Dialog)defretranslateUi(self,Dialog):_translate=QtCore.QCoreApplication.translateDialog.setWindowTitle(_translate("Dialog","豆豆的天气预报"))self.label.setText(_translate("Dialog","选择城市:"))self.comboBox.setItemText(0,_...
以上完成后保存为Weather.ui文件。 2、转换.ui文件为.py文件 PyQt5支持直接使用.ui文件: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 import sys from PyQt5 import QtWidgets, uic app = QtWidgets.QApplication(sys.argv) window = uic.loadUi("mainwindow.ui") window.show() app.exec() 但是...
38xianshi3.move(50,350)39xianshi3.resize(700,80)40xianshi4=QLabel(window)41xianshi4.setStyleSheet('font-size:35px;background-color:orange')42xianshi4.setText('')43xianshi4.move(50,450)44xianshi4.resize(700,80)45defcao():46a=shuru.text()47b=zidian[a]48url='http://www.weather.com....
比如上海市的cityId是101020100,获取天气的API接口就是http://t.weather.sojson.com/api/weather/city/101020100 访问这个地址,返回的数据如下: 因为返回的结果有近15天的天气,所以要对结果做一个遍历,取出今天对应的天气信息。同时天气更新时间为每天的:3点,8点,13点,19点,所以建议不要凌晨去获取,加上CDN有1个...