0
我正在嘗試使用Tkinter。運行我的程序時,應該出現一個彈出按鈕。按下按鈕後,代碼被執行並且網站被解析。解析本身工作正常,但與Tkinter它沒有。此外,代碼在按下按鈕之前執行。如果有人能指出我犯的錯誤,我將非常感激。Tkinter不運行功能
from lxml import html
import requests
from bs4 import BeautifulSoup
def news():
page = requests.get('http://www.globo.com/index.html')
soup = BeautifulSoup(page.content, 'html.parser')
bbb = soup.find_all('p', class_='hui-premium__title')
for item in bbb:
ccc = item.get_text('p')
print(ccc)
from tkinter import *
master = Tk()
b = Button(master, text="latest news", command='news()')
b.pack()
mainloop()
不要使用HTML手工格式化代碼。只需粘貼,選擇它,然後單擊「{}」按鈕或按Ctrl + K。這將它縮進4個空格,告訴Stack Overflow將其格式化爲代碼。 – Chris