首页 > 解决方案 > 在 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 等。

标签: pythontkinter

解决方案


您已将对象链接到标签,您需要调用文本。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()

推荐阅读