Tkinter: How do I change the actual width of a widget?

M

Mudcat

I am trying to change the width of a widget based on pixel size and not
on characters. I can't figure out how to do this.

Normally to change to the size of a widget it looks like:

widget.configure(width = x)

However that is in characters, not in pixels. To retrieve the actual
size of a widget, I believe it is done with:

x = widget.winfo_width()

Obviously that value can not be used in the configure statement. Is
there a way to dynamically change the width (and height) of a widget
using the winfo data?

Thanks,
Marc
 
F

Fredrik Lundh

Mudcat said:
I am trying to change the width of a widget based on pixel size and not
on characters. I can't figure out how to do this.

Normally to change to the size of a widget it looks like:

widget.configure(width = x)

However that is in characters, not in pixels. To retrieve the actual
size of a widget, I believe it is done with:

x = widget.winfo_width()

Obviously that value can not be used in the configure statement. Is
there a way to dynamically change the width (and height) of a widget
using the winfo data?

look for "pack_propagate" on this page for one way to do it:

http://effbot.org/tkinterbook/button.htm

</F>
 
M

Mudcat

Fredrik said:
look for "pack_propagate" on this page for one way to do it:

http://effbot.org/tkinterbook/button.htm

</F>


Thanks!

I had actually seen this, but on the pythonware site where it looks
like this:

f = Frame(master, height=32, width=32)
f.pack_propagate(0) # don't shrink
b = Button(f, text="Sure!")
b.pack(fill=BOTH, expand=1)

I guess somewhere along the way it became necessary to use the pack
function with propagate.As a result, I was having problems getting it
to work and thought I was doing something else wrong.

And I guess I also missed the fact that Tkinter doc updates are being
done on effbot. I just upgraded my python version after a long time,
and I'm finding out all kinds of interesting things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top