#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Help with Opening GIF Images on a New Window by Clicking Button on Horoscope Program


    I need help with the button action for this code. When you click on the button, a new window should open with the GIF image of the horoscope sign. The name of the GIF image files are "Pisces.gif", "Taurus.gif",etc.






    Code:
    from Tkinter import *                #Call all modules for TKinter in order to make GUI.
    
    app = Tk()                          #Define a variable for the TKinter interface. 
    app.title("Horoscope")                 #Apply GUI title
    app.geometry("500x3000")           #Size of window. 
    
    button1=Button(app, text="January 20-Febuary 18",width=20)
    button1.pack(padx=15,pady=15)
    
    button2=Button(app, text="February 19-March 20",width=20)
    button2.pack(padx=15,pady=15)
    
    button3=Button(app, text="March 21-April 19",width=20)
    button3.pack(padx=15,pady=15)
    
    button4=Button(app, text="April 20-May 20",width=20)
    button4.pack(padx=15,pady=15)
    
    button5=Button(app, text="May 21-June 20",width=20)
    button5.pack(padx=15,pady=15)
    
    button6=Button(app, text="June 21-July 22",width=20)
    button6.pack(padx=15,pady=15)
    
    button7=Button(app, text="July 23-August 22",width=20)
    button7.pack(padx=15,pady=15)
    
    button8=Button(app, text="August 23-September 22",width=20)
    button8.pack(padx=15,pady=15)
    
    button9=Button(app, text="September 23-October 22",width=20)
    button9.pack(padx=15,pady=15)
    
    button10=Button(app, text="October 23-November 21",width=20)
    button10.pack(padx=15,pady=15)
    
    button11=Button(app, text="November 22-December 21",width=20)
    button11.pack(padx=15,pady=15)
    
    button12=Button(app, text="December 22-January 19",width=20)
    button12.pack(padx=15,pady=15)
    
    app.mainloop()                                                            #Final input for making GUI
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,856
    Rep Power
    481
    This program works a little bit. Click Taurus to activate the one installed image.
    Code:
    # the image used in this program is the file
    # http://www.gnu.org/graphics/heckert_gnu.png
    # converted to pgm format with the imagemagick command
    # $ convert heckert_gnu.png heckert_gnu.pgm
    # installed into the local directory
    
    import sys
    
    if sys.version[0] == '2':
        import Tkinter as tkinter #load tkinter bypassing some version dependence
    else:
        import tkinter
    
    class TheBeautifulPicture:
    
        def __init__(self, label, filename):
            self.filename = filename
            self.photo = tkinter.PhotoImage(file = filename)
            self.label = label
    
        def __call__(self, *args, **kw2args):
            label = self.label
            label.configure(image = self.photo)
            label.master.deiconify()
    
    Button = tkinter.Button
    label = tkinter.Label()
    label.pack()
    label.master.iconify()
    
    app = tkinter.Tk()       #Define a variable for the TKinter interface.
    app.title("Horoscope")   #Apply GUI title
    app.geometry("500x3000") #Size of window.
    
    pad = dict(padx = 15, pady = 15)
    Button(app, text="January 20-Febuary 18",   width=20).pack(**pad)
    Button(app, text="February 19-March 20",    width=20).pack(**pad)
    Button(app, text="March 21-April 19",       width=20).pack(**pad)
    
    Button(app,
           text="April 20-May 20",
           width=20,
           command = TheBeautifulPicture(label,'heckert_gnu.pgm')
        ).pack(**pad)
    
    Button(app, text="May 21-June 20",          width=20).pack(**pad)
    Button(app, text="June 21-July 22",         width=20).pack(**pad)
    Button(app, text="July 23-August 22",       width=20).pack(**pad)
    Button(app, text="August 23-September 22",  width=20).pack(**pad)
    Button(app, text="September 23-October 22", width=20).pack(**pad)
    Button(app, text="October 23-November 21",  width=20).pack(**pad)
    Button(app, text="November 22-December 21", width=20).pack(**pad)
    Button(app, text="December 22-January 19",  width=20).pack(**pad)
    
    app.mainloop()
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo