[Tutor] Update a button content on click

ANKUR AGGARWAL coolankur2006 at gmail.com
Tue Feb 15 18:14:38 CET 2011


upper code posted earlier  is running fine....

The problem is in the code below bcoz of the height nd width factor...
from Tkinter import *
root=Tk()

photo=PhotoImage(file="Cross.gif")
def ok():
 b1["image"]=photo

b1=Button(root,text="",image=None,height=4,width=4,command=ok)
b1.grid()

On Tue, Feb 15, 2011 at 10:34 PM, ANKUR AGGARWAL <coolankur2006 at gmail.com>wrote:

> from Tkinter import *
> root=Tk()
>
> photo=PhotoImage(file="Cross.gif")
> def ok():
>  b1["image"]=photo
>
> b1=Button(root,text="",image=None,command=ok)
> b1.grid()
> root.mainloop()
>
> Here's my code . Not getting the desired output
>
> On Tue, Feb 15, 2011 at 10:26 PM, ALAN GAULD <alan.gauld at btinternet.com>wrote:
>
>> > b1=button(root,image=None,height=4,width=4,command=ok)
>>
>> This says you want the button to e 4 pixels squarte. Is that really
>> what you want?, because....
>>
>>  and then ok defination is as follows :
>>  def ok():
>>   b1["image"]=photo
>>
>> now problem is that after clicking on the button, image is coming
>> up like a flash and then button becomes almost to zero size.
>>
>> Like to 4x4 pixels maybe, just as you asked?
>> What happens if you change the size to something like 40x40?
>>
>> Also in Tkinter to display an image you usually have to firtst create
>> a PhotoImage object and assign that to the image attribute. It's not
>> clear from your code whether you are doing that or not.
>> Is photo a PhotImage object?
>>
>> I want to retain the height=4,width=4 along with the image after
>> clicking on the button. Image size is smaller than the button size.
>>
>> It sounds like your original size is greater than 4x4 and after setting
>> the image it shrinks to 4x4...
>>
>> HTH,
>>
>> Alan G.
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110215/d1cac8d5/attachment.html>


More information about the Tutor mailing list