[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Changing the size of a Button

K Viltersten

3/9/2008 4:11:00 PM

How do i change the size of a Button
(using Tkinter), other than to set it
during construction?

I've found methods for getting the
size but not applying them.

I've been laborating with .setvar(*)
but i've been unsuccessful.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

5 Answers

Miki

3/9/2008 6:11:00 PM

0

Hello Konrad,

> How do i change the size of a Button
> (using Tkinter), other than to set it
> during construction?
In Tkinter, usually the geometry managers (such as pack) are the ones
who size the widgets.
If you run something like:
import Tkinter as tk

root = tk.Tk()
def change_size():
b["text"] = "More text"

b = tk.Button(root, text="Text", command=change_size)
b.pack()

root.mainloop()

You'll see that the button changes size to accommodate the new text.

HTH,
--
Miki <miki.tebeka@gmail.com>
http://pythonwise.bl...

K Viltersten

3/9/2008 6:46:00 PM

0

>> How do i change the size of a Button
>> (using Tkinter), other than to set it
>> during construction?
> In Tkinter, usually the geometry managers
> (such as pack) are the ones who size the
> widgets. If you run something like:
> import Tkinter as tk
>
> root = tk.Tk()
> def change_size():
> b["text"] = "More text"
>
> b = tk.Button(root, text="Text", command=change_size)
> b.pack()
>
> root.mainloop()

Thanks for the answer.

Unfortunately, that won't help me at all,
since i, apparently, asked the wrong
question. Let me refrain myself.

What i wish to do is to affect the size
of the button but not due to change of
text but due to resize of the frame it
resides in.

This far i've managed to get a callback
to a function as the resize occurs and to
print the sizes. However, i'd like to
assign these values to the button so it
always stays the same width as the frame.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Marc 'BlackJack' Rintsch

3/9/2008 6:59:00 PM

0

On Sun, 09 Mar 2008 19:45:58 +0100, K Viltersten wrote:

> What i wish to do is to affect the size
> of the button but not due to change of
> text but due to resize of the frame it
> resides in.
>
> This far i've managed to get a callback
> to a function as the resize occurs and to
> print the sizes. However, i'd like to
> assign these values to the button so it
> always stays the same width as the frame.

Don't do it yourself, pack with the `fill` argument set to `Tkinter.X`.

Ciao,
Marc 'BlackJack' Rintsch

Peter Otten

3/9/2008 7:04:00 PM

0

K Viltersten wrote:

> What i wish to do is to affect the size
> of the button but not due to change of
> text but due to resize of the frame it
> resides in.

This is done by the layout manager, too:

import Tkinter as tk

root = tk.Tk()
button = tk.Button(root, text="42")
button.pack(fill=tk.BOTH, expand=True)
root.mainloop()

Alternatively, with a grid layout:

button.grid(row=0, column=0, sticky="nsew")
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)

Peter

K Viltersten

3/10/2008 4:20:00 AM

0

>> What i wish to do is to affect the size
>> of the button but not due to change of
>> text but due to resize of the frame it
>> resides in.
>
> This is done by the layout manager, too:
>
> import Tkinter as tk
>
> root = tk.Tk()
> button = tk.Button(root, text="42")
> button.pack(fill=tk.BOTH, expand=True)
> root.mainloop()
>
> Alternatively, with a grid layout:
>
> button.grid(row=0, column=0, sticky="nsew")
> root.rowconfigure(0, weight=1)
> root.columnconfigure(0, weight=1)


Ah, great! I'll try that right away.
After breakfast, of course! Thanks!

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy