0
このようなGUIサブウィンドウを作成して、トップチームのライブフィードバックを列挙して番号付けします。Toplevel()とForループからのラベル出力 - Python 2
私はそれらに番号を付けてラベルを付けましたが、コードだけで動いてもうまく動作しますが、メインウィンドウから開いた新しいウィンドウで実行するのに問題があります。
import io
import base64
import Tkinter as tk
from Tkinter import *
from re import findall
from urllib2 import urlopen
def epl_Window():
epl = tk.Toplevel()
epl.title('Top Ten EPL Team 2016')
url = "http://i.imgur.com/3znCRqH.gif"
image_byte1 = urlopen(url).read()
data_stream1 = io.BytesIO(image_byte1)
pil_image1 = Image.open(data_stream1)
w, h = pil_image.size
tk_image1 = ImageTk.PhotoImage(pil_image1)
label1 = tk.Label(epl, image=tk_image1, bg='black')
label1.pack(padx=5, pady=5)
epl.geometry("500x700")
for index, value in enumerate(EPL_10, start=1):
Label(epl, text=str(index)).grid(row=index, column=1, sticky='W')
Label(epl, text=value).grid(row=index, column=2, sticky='W')
epl.mainloop()
root = tk.Tk()
root.title("Top Ten Lists")
url = "http://i.imgur.com/H1sURuR.gif"
image_bytes = urlopen(url).read()
# internal data file
data_stream = io.BytesIO(image_bytes)
# open as a PIL image object
pil_image = Image.open(data_stream)
# optionally show image info
# get the size of the image
w, h = pil_image.size
### convert PIL image object to Tkinter PhotoImage object
tk_image = ImageTk.PhotoImage(pil_image)
# put the image on a typical widget
label = tk.Label(root, image=tk_image, bg='brown')
label.pack(padx=5, pady=5)
#BUTTON
EPL_B = Button(root, text='EPL Teams', width=10, command=epl_Window)
EPL_B.pack(anchor = "w", side = LEFT)
#EPL RANK
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.mainloop()
私はデフ新しいウィンドウトップレベル()が、ロードするためにそれを変更する方法がわからない問題があると思い
。それを実行するとプログラムがクラッシュする