You can put an image and text on a Tkinter button widget. This small code shows you how. The GIF image file you want to use for the button should be in the working directory, or you have to give it the full path. Incorporate the Python Image Library (PIL) for other image formats.
# create a Tkinter button with an image and optional text # note that Tkinter reads only GIF and PGM/PPM images # for other image file types use the Python Image Library (PIL) # replace the line photo1 = tk.PhotoImage(file="Press1.gif") # with these three lines ... # # from PIL import Image, ImageTk # image1 = Image.open("Press1.jpg") # photo1 = ImageTk.PhotoImage(image1) # # tested with Python24 vegaseat 23dec2006 import Tkinter as tk button_flag = True def click(): """ respond to the button click """ global button_flag # toggle button colors as a test if button_flag: button1.config(bg="white") button_flag = False else: button1.config(bg="green") button_flag = True root = tk.Tk() # create a frame and pack it frame1 = tk.Frame(root) frame1.pack(side=tk.TOP, fill=tk.X) # pick a (small) image file you have in the working directory ... photo1 = tk.PhotoImage(file="Press1.gif") # create the image button, image is above (top) the optional text button1 = tk.Button(frame1, compound=tk.TOP, width=155, height=55, image=photo1, text="optional text", bg='green', command=click) button1.pack(side=tk.LEFT, padx=2, pady=2) # save the button's image from garbage collection (needed?) button1.image = photo1 # start the event loop root.mainloop()
No matter what image I use, I get this error:
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3200, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file
Are you using an image with a GIF format?
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.
write a C++ program which take inputs from the user/keyboard and calculate his ZAKAT.
get the input from user may include
-Amount invested in business
-Amount given to other business partners as loan
-Amount payable to others
I made a prime number finder, it finds the nearest prime that is above and below any integer (Does not work that well with giant numbers.)
Made this in cpp.sh
Why would I need the x=y+1-1;?
x=y; just doesnt seem to work
Why is this?
And I know my coding ...
there are five tables (personTb, addressTb,churchTb) each holds data pertinent to an individual; (personAddress,personChurch) each hold the primary key for the person table and corresponding table IE personAddress holds primary key for addressTb.
both snippets work, my question is; Is my join correctly formatted?
select concat(personTb.p_fName,' ',personTb.p_mName,'. ',personTb.p_lName) ...