在 GUI 中将文本输出为标签而不是打印 Python 2
Output text as Label in GUI rather than printing Python 2
我想创建一个看起来像这样的 gui window,其中列出了顶级团队的实时反馈并为他们提供了编号。我在创建列表框时弄明白了(但我宁愿像图片一样在框架内使用标签或框架框)。
此外,我尝试打印编号并且它适用于打印功能,但我不知道如何使用实际获取的数据实现它以显示为 GUI。
from urllib import urlopen
from re import findall
from Tkinter import *
from Tkinter import Tk, Label, Button
url = 'http://www.bbc.com/sport/football/premier-league/table'
EPL_contents = urlopen(url).read()
EPL_Ranking = findall("'>(\w* ?\w*)</a>", EPL_contents)
EPL_10= EPL_Ranking[:10]
root = Tk()
for index, value in enumerate(EPL_10, start=1):
print index, value
root.mainloop()
任何人都可以告诉我如何继续吗?谢谢
使用 Label
widget to create label, and use grid
or pack
显示标签小部件。
for index, value in enumerate(EPL_10, start=1):
Label(root, text=str(index)).grid(row=index, column=0, sticky='W')
Label(root, text=value).grid(row=index, column=1, sticky='W')
我想创建一个看起来像这样的 gui window,其中列出了顶级团队的实时反馈并为他们提供了编号。我在创建列表框时弄明白了(但我宁愿像图片一样在框架内使用标签或框架框)。
此外,我尝试打印编号并且它适用于打印功能,但我不知道如何使用实际获取的数据实现它以显示为 GUI。
from urllib import urlopen
from re import findall
from Tkinter import *
from Tkinter import Tk, Label, Button
url = 'http://www.bbc.com/sport/football/premier-league/table'
EPL_contents = urlopen(url).read()
EPL_Ranking = findall("'>(\w* ?\w*)</a>", EPL_contents)
EPL_10= EPL_Ranking[:10]
root = Tk()
for index, value in enumerate(EPL_10, start=1):
print index, value
root.mainloop()
任何人都可以告诉我如何继续吗?谢谢
使用 Label
widget to create label, and use grid
or pack
显示标签小部件。
for index, value in enumerate(EPL_10, start=1):
Label(root, text=str(index)).grid(row=index, column=0, sticky='W')
Label(root, text=value).grid(row=index, column=1, sticky='W')