Python: Tkinter not displaying my image or UI -


I am trying to create a user interface with an image in my top right corner This is my code:

  import as tkinter import urllib.request import64 as base64 b64 class my_ui (tk.Tk): def __init __ (self, parent): tk.Tk .__ init __ (self , Parents) self.parent = Parents self-interest () DRAF affinity (self): self. Grad () #Welcome Label = Vaccines Label (self, text = "welcome to my UI", anchor = 'center', FG = 'white', bg = 'blue') label. Grid (column = 0, line = 0, column = 2, line = 2, stick = = 'ew') # button button = vaccine button (auto, text = "button1", command = self.onButtonClick) button. Def OnButtonClick (auto): print ("you clicked the button!") If the __name__ == "__main__": App = my_ui (none) # Logo URL (column = 0, line = 3, sticky = 'w') - Just a smiley face URL = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQCItlNQe0QaiuhkADUwgVTpx-Isaym6RAP06PHkzBe2Yza3a4rYIkHuB8" U = urllib.request.urlopen (URL) Raw_data = u.read () u.close () B64_data = b64.encodestring (raw_data) photo = tk.PhotoImage (data = b64_data) logo = tk.Label (app, image = photo) save it in logo.image = photo # to Memory logo.pack () If I include this line e, the UI works fine, App.ti Tle ('my user interface') app Myoplop ()   

I am pulling .gif from the web and returning a photo image with my function. When I run it, I do not make any mistake - rather, my tanker window does not show anything when I remove the line stated in my comment, without any error, my UI is ok (Button, but no image No) comes.

I'm not sure what the window means in the absence of the window. I'm running Python 3.4.1 on Mac OSX Any help will be very much appreciated!

When a tk.photoImage object gets trash together, the image " Release ", so to speak The image is still being used, so it has not been deleted, but it will be completely empty. << Code> Return Change with:

  photo = tk.photoImage (data = b64_data) Return photo   

Just make sure Be declared as photo as a global variable.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -