| | |
uplaoding an image using a button
Thread Solved |
hi everyone. i'm try to load an image by clicking on a botton insert imag but the problem thata i having with this is that
the image is not being insert it just appear and disappear immediately.
can anyone tell me what is wrong with my codes and tel me how to do it.
thanks...
here is my code
i want when i click on the insert image button the image appear on the canvas.
the image is not being insert it just appear and disappear immediately.
can anyone tell me what is wrong with my codes and tel me how to do it.
thanks...
here is my code
python Syntax (Toggle Plain Text)
import Tkinter as tk from PIL import Image, ImageTk import Tkinter from Tkconstants import * frame=tk.Frame() frame.pack() canvas =tk.Canvas(frame,bg = 'white',width=500, height=500) canvas.pack() def image(): imageFile = "map.png" image1 = ImageTk.PhotoImage(Image.open(imageFile)) canvas.create_image(200, 250, image=image1) canvas.update() button=tk.Button(frame,fg="blue", text="Insert Image", activebackground='red',font=('verdana', 10, 'bold'),command=image) button.pack(padx =50,side = "left") frame.mainloop()
i want when i click on the insert image button the image appear on the canvas.
Please stick to established Python coding rules, you code is hard to read:
python Syntax (Toggle Plain Text)
import Tkinter as tk from PIL import Image, ImageTk def show_image(): """image object image1 created in main""" canvas.create_image(250, 250, image=image1) #canvas.update() frame = tk.Frame() frame.pack() canvas = tk.Canvas(frame, bg='white', width=500, height=500) canvas.pack() button = tk.Button(frame, fg="blue", text="Insert Image", activebackground='red', font=('verdana', 10, 'bold'), command=show_image) button.pack(padx=50, side="left") # create the image object here, not in the function imageFile = "map.png" image1 = ImageTk.PhotoImage(Image.open(imageFile)) """ # default is center the image canvas.create_image(250, 250, image=image1) canvas.update() """ frame.mainloop()
No one died when Clinton lied.
![]() |
Other Threads in the Python Forum
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl pysimplewizard python random recursion redirect remote reverse scrolledtext session simple software sprite statictext string strings syntax table terminal text textarea thread threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






