Alright, I am thoroughly confused. So I recently started to use the Steam API and I decided to start out something simple, displaying the avatar image of a profile.
Thing is, the program runs with no errors except that it does not display the image.
Here is the code where it shows the image:
def displayImage():
global window
global STEAM_USER
response = urllib2.urlopen('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + STEAM_API_KEY + '&steamids=' + STEAM_USER + '&format=xml')
htmlSource = response.read()
soup = BeautifulSoup(htmlSource)
avatar = soup.find('avatarfull').getText()
print avatar
image_bytes = urllib2.urlopen(avatar).read()
data_stream = io.BytesIO(image_bytes)
pil_image = Image.open(data_stream)
tk_image = ImageTk.PhotoImage(pil_image)
label = Label(window, image=tk_image)
label.pack(padx=5, pady=5)
And here is the rest of the code:
import urllib2
from Tkinter import *
from PIL import Image, ImageTk
from bs4 import BeautifulSoup
import io
STEAM_API_KEY = 'XXXX'
global window
window = Tk()
window.title('Steam Avatar Viewer')
window.geometry("215x215")
def newUser():
global window
global entry
entry = Entry(window)
button = Button(window, text='Search', width=10, command=getUser)
entry.pack()
button.pack()
def getUser():
global STEAM_USER
global entry
steamUser = entry.get()
steamConverterURL = 'http://www.steamidconverter.com/' + steamUser
steamIDURL = urllib2.urlopen(steamConverterURL)
steamIDSource = steamIDURL.read()
a = BeautifulSoup(steamIDSource)
for hit in a.findAll(attrs={'id':'steamID64'}):
STEAM_USER = hit.contents[0]
print STEAM_USER
displayImage()
def displayImage():
global window
global STEAM_USER
response = urllib2.urlopen('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + STEAM_API_KEY + '&steamids=' + STEAM_USER + '&format=xml')
htmlSource = response.read()
soup = BeautifulSoup(htmlSource)
avatar = soup.find('avatarfull').getText()
print avatar
image_bytes = urllib2.urlopen(avatar).read()
data_stream = io.BytesIO(image_bytes)
pil_image = Image.open(data_stream)
tk_image = ImageTk.PhotoImage(pil_image)
label = Label(window, image=tk_image)
label.pack(padx=5, pady=5)
newUser()
window.mainloop()
I believe it is something very simple but I can't figure out what's causing the image not to display.