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.

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

Here is the code format.

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

Here is a hint ...

''' toplevel101.py

'''

from functools import partial
from Tkinter import *     

def show_pic(img):
    # create child window
    top = Toplevel()
    Label(top, image=img).pack() 


# create the root window
app = Tk()
#Apply GUI title
app.title("Horoscope")
#Size of window.
app.geometry("500x3000") 

# pick images you have in the working directory or give full path
image1 = PhotoImage(file='1.gif')
cmd1 = partial(show_pic, image1)
button1=Button(app, text="January 20-Febuary 18",width=20,command=cmd1)
button1.pack(padx=15,pady=15)

image2 = PhotoImage(file='2.gif')
cmd2 = partial(show_pic, image2)
button2=Button(app, text="February 19-March 20",width=20,command=cmd2)
button2.pack(padx=15,pady=15)


# modify rest of buttons in similar fashion

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)

# start the GUI event loop
app.mainloop() 

As an exercise you could create all those buttons in a loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.