这行代码应该在Weather Zip窗口中显示一个按钮。问题是只有WeatherZip条目显示,而按钮不显示。 以下是示例代码:
Weather = Tk()
Weather.geometry('350x200')
Weather.title("Weather Finder")
Label(Weather, text = "Enter Zip").grid(row = 0, column = 0)
ZipCode = Entry(Weather)
ZipCode.grid(row = 0, column = 1)
zip_code = ZipCode.get()
ZipButton = Button(Weather, text='CHECK WEATHER!', commmand=checkWeather(zip_code))
ZipButton.grid(row = 1, column = 0)
我相信这不可能用这个狙击手就解决,所以我这里有一个所有代码的链接https://hastebin.com/ibodatifem.py
错误是
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Name\Desktop\Python Stuff\Something.py", line 18, in checkWeather
place = content.findAll("header", {"class": "loc-container"})[0].text
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Name\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Name\Desktop\Python Stuff\Something.py", line 60, in WeatherDef
ZipButton = Button(Weather, text='CHECK WEATHER!', commmand=checkWeather(ZipCode.get())
File "C:\Users\Name\Desktop\Python Stuff\Something.py", line 31, in checkWeather
temp = 'Temp: ' + content.findAll("div", {"class": "today_nowcard-temp"})[0].text
IndexError: list index out of range
我很笨,所以我很感激你的帮助
谢谢, 格特雷克托莱尔斯
尝试更改按钮命令,如此行所示。您不能按当前的方式传递参数,而是使用lambda
相关问题 更多 >
编程相关推荐