Changing the size of a Button

K

K Viltersten

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.
 
M

Miki

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,
 
K

K Viltersten

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.
 
M

Marc 'BlackJack' Rintsch

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
 
P

Peter Otten

K said:
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

K Viltersten

What i wish to do is to affect the size
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!
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top