Tkinter按钮和输入问题

时间:2019-11-25 21:59:10

标签: python tkinter beautifulsoup

这行代码应该在“天气压缩”窗口中显示一个按钮。问题在于仅显示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

我非常愚蠢,所以将不胜感激。

谢谢, GetRektOrElse

1 个答案:

答案 0 :(得分:0)

尝试更改此行的按钮命令。您不能像使用lamsda那样传递args。

ZipButton = Button(Weather, text='CHECK WEATHER!', command=lambda: checkWeather(ZipCode.get())