【问题标题】:Output text as Label in GUI rather than printing Python 2在 GUI 中将文本输出为标签而不是打印 Python 2
【发布时间】:2016-09-06 08:07:47
【问题描述】:

我想创建一个看起来像这样的 gui 窗口,其中列出了顶级团队的实时反馈,并给他们一个编号。我在创建列表框时发现了它(但我宁愿在框架内有标签或框架框,就像图片一样)。

另外,我尝试打印编号,它适用于打印功能,但我不知道如何使用实际获取的数据来实现这一点以显示为 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()

任何人都可以帮助我了解如何进行吗?谢谢

【问题讨论】:

    标签: python user-interface tkinter display


    【解决方案1】:

    使用Label widget 创建标签,使用gridpack 显示标签小部件。

    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')
    

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多