python - 在 tkinter Gui 界面中打印天气更新
问题描述
我想在 tkinter gui 界面上打印条件天气。所以我写了这段代码....
import tkinter as tk
from tkinter import *
from weather import Weather,Unit
win=tk.Tk()
weather = Weather(unit=Unit.CELSIUS)
location=weather.lookup_by_location('Dhaka')
condition=location.condition
label=Label(text=condition)
label.pack()
win.mainloop()
但我想要显示条件的输出,如 Sunny、Thunderstorm 等。
解决方案
您已将对象链接到标签,您需要调用文本。condition.text
import tkinter as tk
from tkinter import *
from weather import Weather,Unit
win=tk.Tk()
weather = Weather(unit=Unit.CELSIUS)
location=weather.lookup_by_location('Dhaka')
condition=location.condition
label=Label(text=condition.text)
label.pack()
win.mainloop()
推荐阅读
- c# - 如果单击行并将其列从 true 更改为 false,我如何在 DataGrid 中检测到,反之亦然?
- javascript - 如何在 javascript 中使用另一个数组中的属性过滤一个数组中的对象?
- angular - 角度条件
- javascript - 在 Javascript 中获取 Bootstrap 的当前主题颜色
- terraform - 如何以编程方式获取 Terraform 模块名称?
- java - BeanNotOfRequiredTypeException:名为 X 的 Bean 应该属于 X 类型,但实际上属于“com.sun.proxy.$Proxy”类型
- rspec - 为 RSpec rails 5 创建未定义的方法
- ios - 将 View 动画到 collectionView 中的选定单元格或 scrollView 中的 tableView
- amazon-s3 - 为什么 october cms 不通过使用 amazon-s3 上传图像将附件保存在 db 上?
- i2c - I2C 通信有什么问题?