Ich möchte ein GUI-Unterfenster erstellen, das so aussehen könnte, die ein Live-Feedback für die Top-Teams auflistet und ihnen auch eine Nummerierung gibt.Toplevel() und Label out put von For-Schleife - Python 2
Also habe ich für die Schleife Funktion getan, um sie zu nummerieren und sie aus, was funktioniert gut, wenn mit nichts als dem Code ausgeführt, aber ich habe Probleme, es auf dem neuen Fenster, das vom Hauptfenster geöffnet.
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()
Ich denke, es Problem mit def neuen Fenster Toplevel ist(), aber nicht sicher, wie es ändern laden zu. Running it make Programmabsturz